Hello, I am creating game in which you have to collect certain items to open a door which loads another scene. This is my first standalone project and new to scripting a lot of it is patch work.
In the level you need to find 4 items to open a door. If you try to click on the door with the score lower then 4 it will not open.
My problem is that if I click on the door it gives me +1 Score.
Even if I have a score of 0 after clicking the door it will give me +1.
if i keep clicking on the door i can get a total of 4 and be able to leave
The items that you need to pick up has a Score.js on it which gives the score, but the door does not, it has a level transfer script on it.
Is there any obvious solutions that I am not seeing?
Score.js
public static var score = 0;
var scoreText = "Fragment: 0/4";
var mySkin : GUISkin;
var CanEnter:boolean = false;
function OnTriggerEnter(coll:Collider){
CanEnter = true;
}
function OnTriggerExit(coll:Collider){
CanEnter = false;
}
function Update(){
if(Input.GetKeyDown("e") && CanEnter){
Debug.Log("OnTriggerEnter() was called");
Debug.Log("Other object is a coin");
score += 1;
scoreText = "Fragment: " + score + "/4";
Debug.Log("Score is now " + score);
CanEnter = false;
}
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Label (Rect (10, 10, 500, 200), scoreText.ToString()); }
door code.
var CanEnter:boolean = false;
function OnTriggerEnter(coll:Collider){
CanEnter = true;
}
function OnTriggerExit(coll:Collider){
CanEnter = false;
}
function Update(){
if(Input.GetKeyDown("e") && CanEnter && Score.score == 4){
Camera.main.SendMessage("fadeOut");
Invoke("LevelLoad", 2);
Application.LoadLevel ("Hallway");
}
}
function LevelLoad()
{
yield WaitForSeconds (40);
Application.LoadLevel ("Hallway");
}