- Home /
This question was
closed Nov 16, 2013 at 06:50 PM by
clunk47 for the following reason:
The question is answered, right answer was accepted
Object reference not set to an instance of an object?
I have the error "Object reference not set to an instance of an object". My script:
function Update ()
{
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray))
{
**if(hit.collider.gameObject.tag == ("RecomendedMenu"))
{
RecomendedMenu.renderer.enabled = true;
}
if(hit.collider.gameObject.tag == ("KojiMenu"))
{
KojiMenu.renderer.enabled = true;
}**
}
}
The "tag" parts of my script are the ones that are getting the error. "RecomendedMenu" is the correct tag and the variable "RecomendedMenu" has been declared. What is wrong?
Comment
Best Answer
Answer by Seregon · Nov 16, 2013 at 02:47 PM
The problem is that your not assigning any information to hit, it remains null, resulting in the error when you try to use it. Changing line 6 to:
if (Physics.Raycast (ray, hit))
should fix that.