How to add and access objects in array?

This is simple but couldn’t find any answers. How do I add GameObjects to an array? isnt it just

var targets : GameObject[];
var oneTarget : GameObject;

targets = oneTarget;

and How to access one of the objects in the array, lets say the seconds one, I tried…


No, your code is attempting to assign a GameObject variable to a GameObject variable, which is impossible. In fact you cannot add anything to built-in arrays; you initialize them with a pre-set number of elements. This can be done in code, or in the inspector. If you want an array where the number of elements can be dynamically changed, use a generic List instead, then you can use List.Add.