Unity With C# script : Class Data Type Passing Value From Class With Data Twice Weird

后端 未结 2 1578
无人及你
无人及你 2021-01-24 11:32

I got a simple Question and weird from passing value to data type class variable.

the code like below :

void AddItem(int ID) {
    for (int i = 0; i <         


        
相关标签:
2条回答
  • 2021-01-24 12:01

    In your constructor:

     this.baseName = folder + "/";  // if folder = "Corps/Lemon" from database.items[i].itemIcon
     itemIcon = this.baseName + itemName; // it will update itemIcon to "Corps/Lemon" + "/" + "Lemon"
    

    Did you get it now??

    You may want to assign itemIcon value directly instead of doing all this.

    Do this in your constructor :

    itemIcon = folder;
    

    Cheers

    0 讨论(0)
  • 2021-01-24 12:14

    In item constructor you are doing it:

    this.baseName = folder + "/";
    itemIcon = this.baseName + itemName;
    

    where folder == Corps and this.baseName == "Corps/Lemon/" and itemName == "Lemon" so you have exactly what you should get.

    0 讨论(0)
提交回复
热议问题