How to make first object in a list special ?

Hello there,

I wonder how can I make the first game object in a list special? What I mean by this, I’d love to edit first gameobject, like enable it’s collider, while for the rest gameobjects in the list would have colliders disabled. I tried everything but nothing works.

set the collider of the first enabled, then disable all others…

lst[0].GetComponent<Collider>().enabled = true;
for(int i = 1; i < lst.Count; i++)
{
    lst[i].GetComponent<Collider>().enabled = false;
}

Note… the loop starts at 1, skipping over the 0 element… the first.

I honestly wonder what you tried…

1 Like

Damn that was too simple :slight_smile: Thank you!

Also, how can I make the same thing in an update ? I will make object pooling, so the first item will go to the last place of the list, but the next item on the list has to become first. So basically I want every new first item on the list to become special

You want what is called a ‘Stack’.

1 Like