x


How Do I Exit Level?

ok so im going to put like a flag at the end of every level called Exit_Flag. What i want is for when my character touches the flag it goes to the next level. Anyone could make me a script for this to work and show me what to do with it? I would really appreciate this. Thanks if you can help.

more ▼

asked Jan 12 '11 at 04:57 PM

Brandon 8 gravatar image

Brandon 8
45 18 21 27

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

1 answer: sort voted first

Make a trigger near your flag. When your player touches it, change level. This can be done with a simple script. You add this script to the trigger. You can then also write what level you want to load when the trigger is entered.

var nextLevel : int;

function OnTriggerEnter(collider : Collider)
{
    if (collider.CompareTag("Player"))
    {
        Application.LoadLevel(nextLevel);
    }
}

Alternatively you can add the script to the player and check if it hit the flag, that way you don't need to edit every level.

function OnControllerColliderHit(hit : ControllerColliderHit)
{
    if (hit.collider.name == "Exit_Flag")
    {
        Application.LoadLevel(Application.loadedLevel + 1);
    }
}
more ▼

answered Jan 12 '11 at 05:05 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

thanks ill give it a try

Jan 12 '11 at 05:26 PM Brandon 8

I have fixed the error in the code. I should have tried it on my machine before submitting it.

Jan 12 '11 at 05:43 PM Statement ♦♦
(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:

x322
x263
x132

asked: Jan 12 '11 at 04:57 PM

Seen: 923 times

Last Updated: Jan 12 '11 at 05:59 PM