The previous project realized the wearing function of the equipment, but there are some imperfections, we must further improve.
There are 2 main things that need to be perfected:
① if the bar is equipped before wearing it, the original equipment needs to be returned to the backpack;
After the ② is successfully worn, it needs to make the appropriate number of items in the backpack-1, if the number is 0, then delete the item in the grid.
The script is as follows:
To implement the function ①, only the code block that detects the condition of the object within the lattice in the dress method in class Equipmentui is updated to:
if (item! = NULL)
{
Inventory._instance. GetId (item.id);
Item. SetInfo (info);
}
This realizes the function of putting the original equipment back into the backpack. (actually not put back, but re-created an object image)
To implement the function ②, you need to update it in the Inventoryitem method:
Class Inventoryitem
{
void Update ()
{
if (ishover)
{
BOOL success = Equipmentui._instance. Dress (ID);
if (success)
{
This.tranform.parent.getcompnent<inventoryitemgrid> (). Minusnumber ();//This method is subsequently built
}
}
}
}
Now start building a counting reduction method
Class Inventoryitemgrid
{
public bool Minusnumber (int num = 1)
{
if (this.num >= num)
{
This.num-= num;
Numberlaber.text = This.num;
if (This.num = = 0)
{
Clearinfo ();
Gameobject.destory (this. Getcompnentinchild<inventoryitem> (). Gameobject);
}
return true;
}
return false;
}
}
This builds the wearable system of the equipment.
UNITY3D-RPG Project Study notes (21)