- Home /
Problem making a Finishzone.
Hi!
I'm trying to make a script that, when the player enter a spot or an objekt he wins. Like a Finishzone. And I want it to load my finalscen.
I tryed to script like this-
function OnCollisionEnter(other : Collision) {
if(other.gameObject.tag == "Player") {
//end game here
Application.LoadLevel (5);
}
}
As you can see my script skills is not that good. :) Please help :) Thanks
Answer by lhk · Oct 26, 2010 at 06:30 PM
Your script needs to be attached to your player object. Then you should make an empty GameObject and attach a collider it. In the Inspector view of the GameObject you can toggle the property isTrigger from your collider on and off. I advice you to set it to on, then your player won't collide with the object but be able to walk "through" it. If you do so you have to use OnTriggerEnter() instead of OnCollisionEnter(). In the manual it says:
function OnTriggerEnter (other : Collider) : void Description
OnTriggerEnter is called when the Collider other enters the trigger.
This message is sent to the trigger collider and the rigidbody (or the collider if there is no rigidbody) that touches the trigger. Note that trigger events are only sent if one of the colliders also has a rigidbody attached.
As the Collider parameter offers the variable other.gameObject too you should be able to reuse your code without further changes.
Your answer
Follow this Question
Related Questions
How do I finish a level and send the player to the next? 3 Answers
Complete Level Script 1 Answer
Food bar help 1 Answer