Hey there! I’m trying to make an array to find objects by name.
Right now I have the following code, which works fine now but won’t work when a username adds new elements to the array:
findWithName [0] = GameObject.Find ("1");
findWithName [1] = GameObject.Find ("2");
findWithName [2] = GameObject.Find ("3");
findWithName [3] = GameObject.Find ("4");
findWithName [4] = GameObject.Find ("5");
findWithName [5] = GameObject.Find ("6");
for (int i = 0; i < arrayI; i ++)
{
findWithName [i].GetComponentInChildren<Text> ().text = SaveTest.stringArray[i];
}
This is why I made the following, the problem is that I CAN’T implicitly convert type ‘void’ to ‘UnityEngine.GameObject’ and I totally understand why but don’t know how to do a for loop to search in an array by the name:
for (int i = 0; i < arrayI; i ++)
{
findWithName [i] = caseFind(i);
findWithName [i].GetComponentInChildren<Text> ().text = SaveTest.stringArray[i];
}
}
public void caseFind(int i)
{
switch(i)
{
case 0:
GameObject.Find("1");
break;
case 1:
GameObject.Find("2");
break;
case 2:
GameObject.Find("3");
break;
case 3:
GameObject.Find("4");
break;
case 4:
GameObject.Find("5");
break;
case 5:
GameObject.Find("6");
break;
case 6:
GameObject.Find("7");
break;
case 7:
GameObject.Find("8");
break;
case 8:
GameObject.Find("9");
break;
case 9:
GameObject.Find("10");
break;
default:
Debug.Log("none");
break;
}
}