how to find gameobject using a varable
i was trying to set values like this and I don't know how I would accomplish this
boxs = new GameObject[7];
for (int i; i<7; i++) {
boxs[i] = GameObject.FindGameObjectWithTag(" box" I );
}
Comment
Answer by Dave-Carlile · Nov 13, 2015 at 01:41 PM
You can use the +
operator to combine strings...
boxs[i] = GameObject.FindGameObjectWithTag("box" + i);
Your example has a space in the tag name, and you've used an upper case I
as well, while your loop variable is a lower case i
. Most programming languages are case sensitive which means i
and I
aren't the same thing.