UNITY3D-RPG Project Study notes (21)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.