Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第1张图片

 

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第2张图片

 

1.Building out an Inventory System &Setup Your User Interface

导入了包,没啥其他的

 

2.Inventory Items

主要介绍:

inventory功能的脚本实现

 

具体实现:

Inventory的样式,上面包括左面的一大格一共是9格装备栏,下面为20格背包格。

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第3张图片

在Monobehaviours文件夹下新建脚本InventoryEntry,用来表示背包数据格式

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第4张图片

 

然后在CharacterInventory脚本内添加功能,实现Inventory功能。

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第5张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第6张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第7张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第8张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第9张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第10张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第11张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第12张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第13张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第14张图片

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第15张图片

 

里面有一些错漏都标注了,主要代表传入装备信息的ItemEntry教程里没说哪儿来的,但应该是点击装备然后信息传入。

脚本里方法总体流程为:把信息加入背包信息dictionary→判定是否为stackable(即非装备可消耗型)→添加到快捷栏和装备栏→点击快捷栏的item后,如果为消耗型消耗,如果为装备型穿上,再点击一次就脱掉。

 

同时修改CharacterStat_SO脚本,增加穿脱装备的仓库显示。

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第16张图片

 

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第17张图片

 

3.Linking Item Actions to Gameplay

主要介绍:

把脚本绑到对应GameObject上。

 

具体实现:

Inventory脚本是挂在Player身上的,把对应格子之类拖入

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第18张图片

 

然后把快捷栏格子触发穿上脱下的方法拖入

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第19张图片

 

运行游戏后点击拾取可看到出现在快捷栏

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第20张图片

 

点击I显示装备栏后可见同时显示在装备栏

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第21张图片

 

点击快捷栏的装备后穿上了

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第22张图片

 

如果修改普通格子的id则点击后也能穿脱

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第23张图片

 

总结:

该Inventory教程内穿脱直接点击,没有拖拽功能,简洁直观。穿脱储存功能写在ItemPickUp里,inventory脚本只写inventory的操作。

Advanced Programming: Unity Game Dev Course(1)-Creating a Character Inventory System in Unity_第24张图片

 

完毕。

 

 

 

 

 

你可能感兴趣的:(•【完整课程】)