First time asking a question but i cannot figure it out… I have a script ( below ) that is getting every gameobject with the tag cage and storing them into an array. Next i want it to get there position and store that into another array but i am getting a null reference exeption… In my scene I have 9 cages in total each at different x positions and yes they do have the cage tag and i can debug.log that and the array does list the 9 cages. The problem is when i try to get the positions. here is my code. thanks in advance
private GameObject[] Cages;
private Vector3[] CagesPos;
public void Start()
{
Cages = GameObject.FindGameObjectsWithTag("Cage");
for (int i = 0; i < Cages.Length; i++)
{
Cages_.transform.position = CagesPos*; //this is the line throwing null reference*_
}
}
Please help!!