I’ve been trying for too long; can someone help?
#pragma strict
var Key : GameObject;
var sound : AudioClip;
public var LevelName ="My level name";
var Unlocked : boolean = false;
if (Key == null) {
Unlocked = true;
}
function OnTriggerEnter () {
if(Unlocked == false){
print("The door is locked.");
}
else{
GetComponent.<AudioSource>().PlayOneShot(sound);
yield WaitForSeconds(1);
transform.Rotate(0,90,0);
yield WaitForSeconds(1);
Application.LoadLevel(LevelName);
}
}
I have a code so that when I touch a key, it gets destroyed. This script is meant to unlock the door when the key is destroyed, but I can’t seem to change the variable ingame.
I used:
if (Key == null) {
Unlocked = true;
}
but the unlocked variable’s checkbox just doesn’t check.
Thank you!