- Home /
Question by
JasonT · Aug 17, 2010 at 01:11 AM ·
iphonenullreferenceexceptionlocation
location of game object on x axis
I am trying to to test with an if statement for when a gameObject is between two different x locations using the following code:
if(spiralY.transform.position.x >= -16 && spiralY.transform.position.x <= 19){ renderer.enabled = true; print("location" + spiralY.transform.position.x); }
I am getting a NullReferenceException error. Is there another way to test the location of a gameObject?
Comment
Check that you actually have spiralY and renderer not null.
Best Answer
Answer by Eric5h5 · Aug 17, 2010 at 01:30 AM
When you get a null reference exception error, you're trying to reference an object that doesn't exist. That code would work, but you have to reference objects correctly by making sure that "spiralY" and "renderer" exist.