I keep getting this error with my code.
NullReferenceException: Object reference not set to an instance of an object
Gui.OnGUI () (at Assets/Essential Scripts/Gui.js:15)
It is on this line:
if(script.selected1 == true)
Here is my code:
var rType = 0;
var script : Selecting_System;
function OnGUI() {
if (GUI.Button(Rect(10,70,50,30),"Click")){
rType = 1;
Debug.Log("Clicked the button with text");
}
if(rType == 1)
{
if(script.selected1 == true)
{
Debug.Log("Success");
}
}else{
Debug.Log("Else");
}
}
I’m trying to get it so that when I click the gui button the variable “rType” is equal to 1. Then I want it so when the variable from another script(selected1) is true and the variable “rType” is equal to 1 it will debug “success” It keeps giving me the error i typed above. If you could critique my script and/or explain why I am getting this error that would be great. Thanks in advanced.