Access to objects using string
Hi, i'm creating simple card game and i have already about 100 textures for cards. First i need to create some database (e.g. attack of each card) and the easiest way to do it is to have some place in the inspector where i could drag and drop each texture matching them with their attack. The problem is that 2d arrays don't show in the inspector so i have to use 12 1d arrays. Then i have a trouble, cause i need some easy way to manage them and id like to know if there is some way to do it with string or sth.
public Texture[] Attack_0;
public Texture[] Attack_1;
public Texture[] Attack_2;
public Texture[] Attack_3;
public Texture[] Attack_4;
public Texture[] Attack_5;
public Texture[] Attack_6;
public Texture[] Attack_7;
public Texture[] Attack_8;
public Texture[] Attack_9;
public Texture[] Attack_10;
void Start()
{
for (int i = 0; i < 11; i++) {
string x = "Attack_"+i;
//some instructions using "x" to manage arrays
}
}
Thanks for any help!
If I understood correctly you need a structure that is a (Dictionary). To put it simply a dictionary consist on a collection of key and value pairs. Given a key you can get the associated value and to store a new element you have to give a key and the value. The key since it is used to indexing the structure must be unique. In your case you could use the string as a key and the Texture as the value.
Another different problem you will find is having such amount of textures loaded in realtime, but that s for later :)