How to modify specific GameObjects in an array of GameObjects?

I want to “select” specific gameObjects in an array of gameObjects. In my case specifically, I want to modify all the gameObjects in the array, excluding the first gameObject (gameobject[0]).

Is there a way to somehow specify gameObject[1 - entire array of gameObjects after 1]? I suppose I would compare it to a range of integers that specify specific positions in the array (1 - gameObjectArray.Length) or something like that.

Try a for loop for (int i = 1; i < myArray.Length; i++){ myArray*.myMethod();* }

–

This is a working solution to my problem, but you should probably resubmit this as an answer instead of a comment. Thanks!

–

1 Answer

1

for (int i = 1; i < gameObjectArray.Length; ++i)
{
gameObjectArray // Do your modification here
}
If you want to exclude more elements or make it more general:
List elementsToExclude = new List(new int[] {0,4,7});

for (int i = 0; i < gameObjectArray.Length; ++i)
{
if (elementsToExclude.Contains(i))
continue;

gameObjectArray // Do your modifications here
}

Great! This works, I just had to remember that in the List we are specifying which gameObjects to exclude not which gameObjects to include in the modifications. Thanks so much!

–