x


How to load next level?

I have this code here:

function Update () {
         if(Input.GetKeyDown=="space")
            Application.LoadLevel("lvl2");
}

How can i load to the scene "lvl2"? I attached this script to the First Person Controller.

more ▼

asked May 13 '12 at 06:10 PM

s_aint47 gravatar image

s_aint47
82 6 10 10

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

2 answers: sort voted first

As Bérenger said make sure to have the level "lvl2" added in the build settings.

Normally you would detect input like this and not like you did:

function Update () {
    if(Input.GetKeyDown("space"))
        Application.LoadLevel("lvl2");
}

Give this a try and see if that fixes anything.

more ▼

answered May 13 '12 at 07:04 PM

OrangeLightning gravatar image

OrangeLightning
5.4k 47 57 113

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

By pressing space. Make sure you actually have a scene called lvl2 added to the build.

more ▼

answered May 13 '12 at 06:13 PM

Berenger gravatar image

Berenger
11.2k 12 19 54

good one... but it does not work, also i have the scene named lvl2

May 13 '12 at 06:16 PM s_aint47

Add a print before the LoadLevel to make sure the input is detected. Go in file->Build Settings and make sure lvl2 is added in the "Scene in Build" part. If it still doesn't work, use the id instead. If it still doesn't work, something is wrong with the matrix.

May 13 '12 at 06:26 PM Berenger
(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:

x744
x455
x312

asked: May 13 '12 at 06:10 PM

Seen: 1465 times

Last Updated: May 13 '12 at 07:04 PM