- Home /
Set boolean to true from another scene
Hello guys I'm making an unlocking level system for my game. I want that when the player enters on a onTrigger sets the value to true of l1unlocked. Here is the script
#pragma strict
var l1unlocked = false;
var unlockedt = Texture2D;
var lockedt = Texture2D;
if (l1unlocked == false)
renderer.material.mainTexture = lockedt;
} else {
renderer.material.mainTexture = unlockedt;
}
function OnMouseUp(){ //only if level is unloked if is locked can't load level
Application.LoadLevel(2);
}
I also want to load the scene only if the level 1 is unlocked. I need a script that sets the l1unlocked to true using the function OnCollisionEnter and makes the scene loadable.
Comment
Use the scrpt that will not be dostroyed :
//GlobalVariables.js
var myBool : boolean = false;
function Start(){
DontDestroyOnLoad(gameObject);
}
And then in your On$$anonymous$$ouseDown() method
function On$$anonymous$$ouseDown(){
if(globals.myBool)
Application.LoadLevel(2);
}
Have a look at the PlayerPrefs. They are accesible from anywhere.
Answer by zalan · Aug 18, 2014 at 10:23 AM
You can use static variables which are shared between scenes.