- Home /
Question by
gian_unity190 · Feb 06, 2020 at 07:05 PM ·
listgetcomponentincorrect
can't find List index and pick a object with that index.
I'm using the command: "for (int i = 0; i < CubeSpawner.GetClone(int index); i++) { if (CubeSpawner.GetClone[i].object == colPlayer) { "
to check for a specific object in a list (this is the command that is not working) and the list is public with the command in Cube spawner: "public static Transform GetClone(int index) { return clones[index]; }" but I don't know how to get the index like this (so how many objects the list contains). and how to get a specific object from it (so with [i])
Comment
Best Answer
Answer by unity_ek98vnTRplGj8Q · Feb 06, 2020 at 08:17 PM
Add GetCloneCount() to your CubeSpawner class
public static Transform GetClone (int index) {
return clones[index];
}
public static int GetCloneCount () {
return clones.Count;
}
Now you can loop through the list and get each object 1 by 1 like this
for(int i=0;i<CubeSpawner.GetCloneCount(); i++){
Transform clone = CubeSpawner.GetClone(i);
}