Unity3d Game Development Backpack System (III)

Source: Internet
Author: User

Backpack System (III)

10, modify the item script, complete the item number plus 1 function

Public Uisprite Sprite;

Public UILabel label;

Private int count = 1;

Public void Addcount (int number)

{

Count + = number;

Label.text = count + "";

}

11, modify the grid script, complete the current game item name and we picked up the name of the game items, the number of items plus 1; the name of the current game item is different from the name of the game item we picked up, add the item "Dog planing learning net" to the new lattice.

bool flag = false;

for (int i = 0; i < cells.) Length; i++)

{

if (Cells[i].transform.childcount > 0) //There are items in the current grid

{

knapsack kn = cells[i]. getcomponentinchildren<knapsack> ();

//The name of the current game item is the same as the name of the game item we found .

if (Kn.sprite.spriteName = = name)

{

Flag = true;

Kn. Addcount (1);

break;

}

}

}

//The name of the current game item is not the same as the name of the game item we picked up

if (flag = = false) {

for (int i = 0; i < cells.) Length; i++)

{

if (Cells[i].transform.childcount = = 0) //There is no backpack in the current grid

{

gameobject go = nguitools. AddChild (Cells[i], item); //Put the newly-created backpack inside the grid

Go. getcomponent<uisprite> (). spritename = name; //Add a name for the newly generated backpack

Go.transform.localPosition = Vector3. Zero; //Center The Backpack

break;

}

}

}

Unity3d Game Development Backpack System (III)

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.