OnTriggerEnter does not work?
In my game I've set a tracking shot of the game world, which is a seperate unity file. However I've set a trigger at a specific point and after the camera has entered this trigger, the level, which is another seperate unity file, should load - but it does not. (yes, I've added all the levels in the "Build Settings")
I've been spending hours in trying to fix this but without success - hopefully anybody of you guys got an idea what could be wrong with code:
#pragma strict
public var checkenter : boolean = false;
function Start () {
}
function Update () {
if (checkenter == true) {
Application.LoadLevel("Level Jumper - Level1");
}
}
function OnTriggerEnter () {
checkenter = true;
}
Thanks a lot for your help in advance!!
Answer by Landern · Aug 31, 2015 at 05:52 PM
You're missing the parameter for the function:
function OnTriggerEnter(other : Collider)
{
// stuff
}
Unity Engine needs to be able to match the function with parameters.
Edit: updated to use unityscript parameter and not c#, my mistake.
hmm I just tried that but then I get this error: "BCE0043: Unexpected token: other."
Do I have to define other?
sry but I'm quite a beginner ....
now I have no errors, but unfortunately the trigger still doesn't work :(
Edit:
I've forgot to put the RigidBody component on the object. It works fine now. thank you very much!
Answer by hexagonius · Aug 31, 2015 at 08:24 PM
the parameter is only necessary if you needed information about the object you triggered or collid with. The method function also works without.
This is true, it can match without the argument/parameter. I make it general rule that what the original poster posted might not reflect what they are actually building in the game assembly, thus the most used concept is with a collider reference passed into the method.
Your answer
Follow this Question
Related Questions
PLAYER NOT ACTIVATING TRIGGER WHEN ON TOP OF THE COLLIDER! IS THIS A BUG 0 Answers
Trigger code gives error 0 Answers
OnTriggerEnter 2 Answers
Teleportation script isn't working correctly when I go through my object trigger, I don't know why. 0 Answers
Collider not turning into trigger when painted to a scene 1 Answer