Access specific GameObject in arrays

(Insert greeting here) :slight_smile:

I am some what new to Unity started two months back and I recently started learning about arrays and I now have a general understanding of said thing.

I did a search here on UA on how to access a GameObject in a array, but as I said I am pretty new so I do not really understand all of it so I decided to ask my own question.

I do not know how to access and use a gameObject in a array what I have tried is like so:

var weapons : GameObject[]; // Array holding all the weapons

function Update ()
{
weapons.m16.SetActiveRecursively(false); // m16 is the name of the weapons that is going to be stored in the array.
}

But it says m16 is not a member of weapons. And of course it is not I know that, but I do not know what else to do.

So my question is: How do I get access to a object in a GameObject array and use it.

Thank you. :slight_smile:

The same way you access anything in an array, by the index.

weapons[0].SetActiveRecursively(false);