- Home /
Scene change on collision script?
So I got a script that's supposed to change the scene when the player collides with a certain block but it does nothing. But, when I toggle "Is Trigger" on the box collider, it will load the level and nearly IMMEDIATELY go to the scene i'm trying to go to.
function OnTriggerEnter(other : Collider)
{
Application.LoadLevel("message");
}
It's javascript and the level name i'm trying to change to is called "message".
@zharik86 Still not working. These are my settings in the inspector: http://gyazo.com/a30138678782235a384b55f9c6bd80cf
I don't see how that code even compiles. Application.LoadLevel is with capital "L"'s:
http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html
its cause of javascript. C# would flame you so much you would die from burning.
After you uncheck the trigger checkbox, can you output some kind of string to the console and see if it even detects the collision?
Did you add the level "message" to the build scenes? $$anonymous$$aybe that's why it doesn't load
Answer by AidanHorton · Sep 06, 2014 at 03:50 PM
The reason that your scene will load instantly, is probably because the character is colliding with the floor, which counts as OnTriggerEnter(). A way around this may be something like this:
function OnTriggerEnter(other : Collider) {
if (other.gameObject.tag == "block") {
Application.Loadlevel(0);
}
}
Now obviously you would need to change the level thats being loaded (change the '0'), but also you need to tag the certain block with the tag "block", so that on a collision, if it detects a gameobject with the tag "block", then it loads the level. I haven't tested the code, but i'm sure some Googling would solve the problem. You could also try OnCollisionEnter(collision : Collision), and then do collision.gameObject.tag, but yet again I haven't tested it.
Your answer
Follow this Question
Related Questions
Scene Change Collision 2 Answers
how do you change a scene ingame? 1 Answer
How do I make a scene change when my Player collides with a item? 1 Answer
Scene Change on Player Collision 1 Answer
1 collider 2 fuctions, how? 1 Answer