- Home /
How to change scenes by touching objects?
So I have multiple scenes in my game, and I want to have the player move between them by walking into a certain object (a mesh). How do I set this up where it changes the scene by detecting a collision? Thanks!
Answer by getyour411 · Sep 16, 2013 at 12:29 AM
Essentially:
OnCollision {
Application.LoadLevel("SceneName_in_BuildSettings_or_#");
}
Thanks! It gave me the error "BCE0005: $$anonymous$$ identifier: 'OnCollision'."
So I modified it with another script I saw on here:
var target : Transform;
function OnCollisionEnter( collision : Collision ) {
Application.LoadLevel("0011");
}
and it "works" without errors - but it doesn't change the scene. :/ What am I doing wrong? (Sorry, I'm still a noob at JavaScript)
I've also tried this variant:
var collisionObject : GameObject;
function OnCollisionEnter(collision : Collision){
if (collision.gameObject.name == collisionObject){
Application.LoadLevel("0011");
}
}
and changed the GameObject in question to a rigidbody, as where I got that script from suggested.....but it still doesn't work. :/
In your game's Build Settings, do you have a level named "0011" (literally)? If you use the quotes, it has to match the string name, without quotes it matches the # in the Build Settings.
Answer by Mrawesome109 · Jan 10, 2018 at 01:38 AM
var collisionObject : GameObject;
function OnCollisionEnter(collision : Collision){ if (collision.gameObject.name == collisionObject){ Application.LoadLevel("0011"); } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613114236im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How would I detect water level at the player's position? 2 Answers
Loading player location in a scene 2 Answers
Will a mesh collider work as a parent of several meshes? 1 Answer
Add material and collider to a mesh imported from AutoCAD 0 Answers
Why does my trigger-collider receive Enter but not Stay or Exit? 1 Answer