x


How To Change Scene Through A Collision?

Thanks for taking the time to help me out I just need to change scene on a collision I already have this code in JavaScript

function  OnCollisionEnter  (collisionInfo : Collision) { if (collisionInfo.gameObject.tag == "finish"){//Change Scene
        Application.LoadLevel("City");
     }
    } 

but this does not work at all

more ▼

asked Oct 23 '10 at 06:00 AM

SoulWolf gravatar image

SoulWolf
1 2 2 2

Question what error do you get if any?

Oct 23 '10 at 06:36 AM slkjdfv

no error but nothing happens

Oct 24 '10 at 01:05 AM SoulWolf
(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest

You should use a OnTriggerEnter function like this:

function OnTriggerEnter(other: Collider) { if (other.gameObject.CompareTag == "Player"){ Application.LoadLevel("City"); } }

and make the collider a trigger, so when the player touches the trigger, it will load up the level. hope this helps

more ▼

answered Dec 16 '10 at 11:46 AM

MonkeyAssassin8 gravatar image

MonkeyAssassin8
271 35 38 43

(comments are locked)
10|3000 characters needed characters left

If nothing happens at all the error is probably that the Collision is not triggered (wrong rigidbody/collider setup) or you didn't set the tag for your gameObject correctly. To see how to correctly setup collisions look at the manual. There's a "collision matrix" at the end of each collider's reference page.

In short if you want to receive a collision event one of the two colliding objects will have to be a non-kinematic (dynamic) rigidbody. The other must be a Collider (not a trigger).

more ▼

answered Oct 23 '10 at 07:01 AM

StephanK gravatar image

StephanK
6k 39 53 93

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2490
x532
x13

asked: Oct 23 '10 at 06:00 AM

Seen: 2232 times

Last Updated: Oct 23 '10 at 06:00 AM