- Home /
This question was
closed Oct 21, 2013 at 02:43 PM by
lemiwinks for the following reason:
The question is answered, right answer was accepted
Question by
lemiwinks · Oct 21, 2013 at 02:29 PM ·
gameobjectif-statements
making an "if gameobject is still in scene" statement
hey all, so im just doing a bit of debugging and one ive come across is an error like this
"The object of type 'GameObject' has been destroyed but you are still trying to access it."
now the line in question to this error is this >
transform.position = Vector3.Lerp(transform.position, target.transform.position + new Vector3(-distance, distance, -distance), 0.5f * Time.deltaTime);
now i realise that the script is trying to access my main gameobject but cant because it was deleted, my question is what statement would i need to say "if gameobject exists".
thankyou
Comment
Best Answer
Answer by vexe · Oct 21, 2013 at 02:35 PM
How about:
var go = target.gameObject;
if (go == null)
print ("target is destroyed, no longer exists");
else
print ("IT'S ALIVE!");
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Rotation help! 1 Answer
GUI controlling other game objects 0 Answers
Making script only effect one gameobject when attached to multiple 2 Answers