I am trying to call a specific variable, but I am trying to call it by providing its name FROM another variable.
I don’t exactly know what to search to find it, I tried Reflection and reviewed Multithreads, but none of it helps me.
I have an inventory handling script, that displays the inventory, and I am trying to do this…
Calling Method:
Texture2D inventory_1_texture; //creates a new empty texture variable.
int inventory_1_id = 1; //this sets the item object to 1.
//call the following...
inventory_1_texture = game.GetComponent<EveryItem>().item_ + inventory_1_id + _icon; //load icon from the preset item variable.
In the EveryItem script, I have public variables set for each item id, like so.
public string item_1_name = "Logs";
public Texture2D item_1_icon;
public string item_2_name = "Ash";
public Texture2D item_2_icon;
public string item_3_name = "Bow";
public Texture2D item_3_icon;
How can I call these variables with a code similar to my calling method? Based on a dynamic variable?