- Home /
OnTriggerEnter to load new level
Hi, I'm making a game where the player collects fruit, and must collect a certain amount to proceed to the next level. I have a cube at the moment as the end of level, where i'm trying to make it as a trigger to go to the next level if the player has 3 points, and go to a game over/retry scene if the have under 3. I have set the cube collider as a trigger, and this is my code:
var Counter : int = 0;
var fruit : int = 3;
function Update () {
guiText.text = "Score is: "+Counter;
}
function OnTriggerEnter(col : Collider){
if(col.gameObject.tag == "end")
if (gameObject.name == "Player")
if (Counter == 3)
Application.LoadLevel("level2");
else if(col.gameObject.tag == "end")
if (gameObject.name == "Player")
Application.LoadLevel("gameover");
}
Nothing seems to be happening when passing through the exit cube, which is tagged as "end".
If anyone could help that would be great! Thanks in advance.
Answer by insominx · Jan 30, 2013 at 08:16 PM
At least one of the objects needs to have a RigidBody component on it as well as a collider and you also need to have your collider marked as IsTrigger. See here: Unity Tips and Tricks
Your answer
Follow this Question
Related Questions
getting loading progress for a level 1 Answer
Use the GUITexture to go to the next scene 1 Answer
Level Segmenting and Loading 1 Answer
Door that changes level on character collision script help? 1 Answer
enable a canvas on trigger 2 Answers