Hi guys, i need some help here.
i want to get variable from another scene, but there’s some error and i don’t understand the error.
i have “sceneCity with scriptCity” and “sceneShop with scriptShop”.
in sceneCity i drag “gameObject with scriptShop” to " var sceneShop in sceneCity inspector".
this is the step what variable i want to get :
- when i click on shop button in sceneCity, i will move to sceneShop.
- in sceneShop, when i click cube button, my variable isCube become true and i will back into sceneCity.
- in sceneCity, i will print variable isCube after i click buy button at sceneShop
This is the error :
NullReferenceException: Object reference not set to an instance of an object
scriptCity.Start () (at Assets/scriptCity.js:42)
This is my script for sceneCity :
var sceneShop : scriptShop;
var isCube : boolean;
function Start () {
sceneShop = gameObject.GetComponent(scriptShop);
isCube = sceneShop.isCube;
print(isCube);
}
function OnGUI () {
if(GUI.Button(Rect(Screen.width / 2 + 220, Screen.height / 2 + 165, 50, 30),"Shop")){
Application.LoadLevel("sceneShop");
}
}
This is my script for sceneShop :
var isCube : boolean = false;
function OnGUI () {
if(GUI.Button(Rect(Screen.width / 2 - 100, Screen.height / 2 + 30, 50, 25),"Cube")){
isCube = true;
Application.LoadLevel("sceneCity");
}
}
Hope you guys will help me.
Thanks ![]()