
How is this possible? I set break points to figure this out. If the object is NOT null, jump in to the IF statement. So the break point jumped into it and stopped. But when I I inspect the object you can see in the photo that it is ‘null’?
I set the GameObject variable in the global area.
GameObject redArrowObject;
Here is the whole method and the redArrowObject is not found anywhere else in the script.
void LateUpdate(){
if(redArrowObject != null){
redArrowObject.transform.position = new Vector3(Camera.main.transform.position.x, 300f,0f);
}
if(arrowOnScreen && !redArrowObject){
redArrowObject = GameObject.FindGameObjectWithTag("redArrow").transform.GetChild(0).gameObject;
redArrowObject.transform.position = new Vector3(Camera.main.transform.position.x, 300f,0f);
}
}
What I am trying to do is get a reference to the GameObject so I am not calling it Find function every time.
I’m stumped???