- Home /
Trigger won't load next level when Player enters it
I have a 2D side-scrolling platformer where a skater is jumping over crates. At the end of the level, I need the player to advance to the next level. The problem is that none of the scripts I've tried work. I have a plane sitting vertically for the player to enter and activate. On the plane, I have this script:
var levelLoaded : int;
function OnTriggerEnter(other : Collider){
Application.LoadLevel(levelLoaded);
}
The plane has a box collider on it, and "is trigger" is checked. The skater has a box collider and a rigidbody so it can collide with the crates (rigidbodies and box colliders). Anyone know why the script won't work?
I found the answer! The skater has to be moving for whatever reason. All of the other objects are moving instead of the skater because I'm stupid and that's what I wanted to do. So, I just made the skater have a line of code that moved him 0.001 units forward.
1/ check the trigger is working :
var levelLoaded : int;
function OnTriggerEnter(other : Collider){
Debug.Log( "Trigger was entered by : " + other.gameObject.name );
Application.LoadLevel(levelLoaded);
}
2/ make sure your levels are in the build setting menu : http://docs.unity3d.com/Documentation/$$anonymous$$anual/PublishingBuilds.html
Have you added your scene to the build? Did you give a value to levelLoaded?
Answer by Imankit · Apr 18, 2013 at 04:49 AM
You have to write :
var levelLoaded : int;
function OnTriggerEnter(other : Collider){
if(other.gameObject.name == "skater"){
Application.LoadLevel(levelLoaded);
}
}
i don't think thats the problem. OnTriggerEnter is called when a rigidbody enters the trigger (ANY rigidbody). The if statement would become necessary if he wanted to distinguish different types of colliders.
Your answer
![](https://koobas.hobune.stream/wayback/20220613100531im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add to a 3D object's length through code? 1 Answer
Overlap point of 2 kinematic colliders 1 Answer
How to add the right amount of points when my player destroys a gameobject? 0 Answers
Receiving information about getting hit by a Raycast 2 Answers
How do you execute Trigger-collider collision only in one gameobject? 1 Answer