- Home /
Trying to proceed to next level when multiple items have collided
Blockquote
var score : int 0;
var gui : GUISkin;
var buttonReady : boolean = false;
function OnTriggerEnter(other : Collider ) {
if (other.tag == "item") {
score += 1;
Debug.Log("Score is now " + score);
}
}
function Update () {
if ( score > 5) {
Application.LoadLevel (0);
}
}
I have this script that I am trying to use to change a level when 6 of these objects are touching the object that has the script attached. Unfortunately I cannot get it to work, can anyone help?
How is this not working? Are you not getting any triggers? Are you getting some triggers but not all?
It won't even let me run it, in the console it is expecting a semicolon but I can't see where
Answer by robertbu · Jul 13, 2014 at 03:21 PM
You are just missing an '=' in the first line. The line should be:
var score : int = 0;
Note when posting compiler errors, please include a copy of the error from the console. It tells us what line is having the problem and the stack trace.
Also, I suggest always having '#pragma strict' at the top of the file. It can make for better performing code and will cause some runtime errors to be found at compile time.
The game will run now but it seems to still not be working.
Again you need to be specific. "Not be working" is not enough for us to figure out your problem (beyond some educated guesses). Are you getting some trigger events or no events? How are you moving your character? Etc.
Do you actually have a scene set up in your build settings as level zero ?