- Home /
It says "Null reference exception : Object reference not set to an instance of an object"
The code doesnt have any errors apart from this , But when i play it nothing happens either , what i tyring to do is turn off the Acog mesh for my gun , and turn on the iron sights for my gun . same with the acog on , sights off when i press 1 or 2 heres the code
var attachmentOne : GameObject;
var attachmentTwo : GameObject;
function Update ()
{
if ( Input.GetButtonDown("Disable1"))
{
attachmentOne.Renderer.enabled = false;
}
else
{
attachmentTwo.Renderer.enabled = true;
}
if ( Input.GetButtonDown("Disable2"))
{
attachmentTwo.Renderer.enabled = false;
}
else
{
attachmentOne.Renderer.enabled = true;
}
}
Answer by DaveA · Aug 02, 2013 at 07:58 AM
Assuming you assigned attachmentOne and attachmentTwo via the Inspector, you should use small 'r':
attachmentOne.renderer.enabled; // for example
Answer by ArmarageX · Aug 02, 2013 at 08:26 AM
That error means that your VARIABLES have not been assigned in the inspector.... and if it has.... chances are it HASNT on another object (chances are another object also has the code attached... maybe accidentally, and you just need to remove the script from that object.)
Your answer

Follow this Question
Related Questions
Game Glitches and Cheat Codes 3 Answers
i want an object rotate 45 degrees more than an other one 1 Answer
Faulty Code. 2 Answers
How will we enable and disable a gui texture in unity 3d? 5 Answers
how to disable patent components incode 0 Answers