Long story short. I need to get the Vector3 value of a number of objects and put all of them in an array. For each Game Objects I need to run the following code:
public class Pos : MonoBehaviour {
public Vector3 pos;
// Update is called once per frame
void Update()
{
pos = transform.position;
}
}
And the code that stores all the values in an array is the this other one:
public class GetPos : MonoBehaviour {
public Vector3[] Pos = new Vector3[41];
//get all the space objects
GameObject Go = GameObject.Find("Go");
GameObject Mediterranean = GameObject.Find("Mediterranean");
private void Start()
{
//be able to call all the game objects
Pos GoPos = Go.GetComponent<Pos>();
Pos MedPos = Mediterranean.GetComponent<Pos>();
//make pos contain all possible positions.
Pos[0] = GoPos.pos;
Pos[1] = MedPos.pos;
}
}
I'm not sure why, but whenever I run the code, all of the values of the array Pos are equal 0. What am I doing wrong and how do I fix it?
P.S. There are more objects which need values than what I mentioned(41 in total), but once I get one, it's basically a copy paste job.