- Home /
Scene Change OnCollision Not Working
I am trying to make the scene change when the character collides with an object like a door, but it won't work and their are no compiler errors. Here is the script: function OnCollisionEnter( collision : Collision ){
if (collision.gameObject.tag == "Player"){
Application.LoadLevel ("s2");
}
}
Edit
Here is a working script I found:
function OnTriggerEnter (other : Collider) {
//Check to see if a player entered the door.//
if (other.gameObject.CompareTag("Player") && Input.GetKey(KeyCode.E)) {
Application.LoadLevel("scenename");
}
}
Answer by kingsman141 · May 07, 2013 at 01:50 AM
Try this:
function OnCollisionEnter( collision : Collision){ if(collision.GameObject.tag == "Door"){ Application.LoadLevel("s2"); } }
And apply this to the player. What I did was change gameObject to GameObject and "Player" to "Door" so the thing the player collided with (GameObject) has its tag checked to see if it is "Door".
It's still not working. I tried that and walked into the object and it didn't work. I even turned on Is Trigger and tried it. Thanks though
Answer by Casper091 · Sep 01, 2013 at 04:49 AM
make sure the load colider is set to trigger, and try
function OnTriggerEnter(hit : Collider) { if(hit.gameObject.tag == "Player") { Application.LoadLevel("s2") } }
This worked for a gui activator i used, hope it helps :)
Your answer
Follow this Question
Related Questions
Go through door, by loading next scene, with key-press 1 Answer
door opening 3 Answers
Opening door with the same key? 1 Answer
Access navmeshagent calculation data? 0 Answers
Door Width Gets Smaller When Rotated 0 Answers