Hi guys,
I’m new(ish) to unity and… need some help here.
My brain says something like this “should” work but it looks like unity doesn’t really like it :
void Update () {
//Oject that flies across screen from right to left
GameObject obs;
float leftScreen = Camera.main.orthographicSize * -1f;
obs = Spawn ();
//Shouldn't the below keep track of the position of obs?
Debug.Log (obs.transform.position.x);
}
//Spawning method
private GameObject Spawn () {
int r = Random.Range (0, goList.Count);
Particle = true;
return Instantiate (partList [r], new Vector3 (Camera.main.orthographicSize+10, 0, 0), Quaternion.identity) as GameObject;
Debug.Log (partList [r].transform.position.x);
}
So what I need is an object that flies across the screen (camera view) from right to the left and when the object goes beyond the left side of the screen i want it to do a Destory (obs) on it.
But when I used obs.tranform.position.x it seems like unity isn’t keep a track of obs dynamically and only gets the starting point…
Is there any tips on what I may be doing wrong here and could you guys help me out?
Thanks in advance.