- Home /
NullReferenceException
i really don't understand why this error come to me so much times x.x i could handle it 2-3 times, but now i can't handle it again.. although i have build the exact same code with the last one..
so my code is guiSchool3.js (This script attached to Main Camera on Scene "A")
#pragma strict
var script : guiSchool2;
var choice : int;
script = GetComponent(guiSchool2);
choice = script.flag;
var tekstur1 : Texture;
function Start () {
}
function OnGUI(){
if(choice==1){
GUI.DrawTexture(Rect(Screen.width*0.125,Screen.height*0.125,Screen.width*0.75,Screen.height*0.75),tekstur1);
}
else if (choice==2){
}
}
and here's guiSchool2! (i delete the part that not linked by the error)(This Script attached to Main Camera on Scene "B")
#pragma strict
var flag: int;
function OnGUI (){
GUI.DrawTexture(Rect(posbg_w,posbg_h,bg_w,bg_h),bg);
if(GUI.Button(Rect(pos_b1w,pos_b1h,b_width,b_height)," ",button_perkalian)){
flag = 1;
Application.LoadLevel("School3");
}
if(GUI.Button(Rect(pos_b1w,pos_b2h,b_width,b_height)," ",button_luas)){
flag = 2;
Application.LoadLevel("School3");
}
if(GUI.Button(Rect(pos_b1w,pos_b3h,b_width,b_height)," ",button_satuan)){
flag = 3;
Application.LoadLevel("School3");
}
}
and the console throw me this exception
NullReferenceException: Object reference not set to an instance of an object guiSchool3.Main () (at Assets/Scripts/School/guiSchool3.js:5)
i believe i've done the exact same with the code before.. but it's still wrong.. why?
Please indicate exactly where the error occurs. At line 5 at both scripts it's impossible.
did you even read the error? (at Assets/Scripts/School/guiSchool3.js:5) it is on guiSchool3.js which is the first code..
i still looking for the right answer thou, and still couldn't figure out why its error..
Answer by AwesomeFaceHD · Jan 14, 2014 at 10:06 PM
I'm pretty sure you should assign "script" and "choice" in the start function. Unless you already fixed it.
function Start() {
script = GetComponent(guiSchool2);
choice = script.flag;
}
i've put it there, but the error still comes out.. i really don't understand why this happens.. maybe another way to solve this?
Your answer
Follow this Question
Related Questions
Object reference not set to an instance of an object help (JS) 0 Answers
Object reference not set to an instance of an object 1 Answer
Hi I get an error code when i'm using my Javascript and I can't understand how to fix it... :( 1 Answer
NullReferenceException: Object reference not set to an instance of an object 1 Answer
[js]NullReferenceException: Object reference not set to an instance of an object 1 Answer