x


pressing key - changing scene

Hi,

i'm a bloody newbie using unity3, but advanced in 3d. currently I'm working on a kind of an art-fps-game for a performance on stage. i need to change the levels manually at a certain time, so my first idea was to use keys switching to the levels, i.e. key #2 for level 2, key #3 for level 3 and so on...

i have no idea how to solve this?

glad for any suggestions: andreas

more ▼

asked Jul 27 '10 at 02:51 PM

ama gravatar image

ama
1 1 1 1

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

1 answer: sort voted first

Hi,

You could use something along those lines, using F2 and F3 keys:

function Update(){

If (Input.GetKey(KeyCode.F2)){
Application.Loadlevel("level2")
}
else if (Input.GetKey(KeyCode.F3)){
Application.Loadlevel("level3")
}

}
more ▼

answered Jul 27 '10 at 03:02 PM

Thaelvyn gravatar image

Thaelvyn
63 1 1 6

wow, thanks for that quick reply. i think i understand your codesnippet. thanks. last stupid question: where do i have to put that code to? :)

Jul 27 '10 at 03:15 PM ama

put that in a script attached to a permanent element of your scene. Or you can as well create an empty GameObject, rename it "levelChange" for example and add the script with this inside (it's Javascript). That should do the trick for you. Be sure to have that "levelChange" GameObject in all your scenes :)

Jul 27 '10 at 03:26 PM Thaelvyn

You missed a few semi colons, you need : Application.Loadlevel("level2");

Jul 27 '10 at 04:19 PM Fishman92

hi there, thank u very much for your help. so i entered this code onto an empty GameObject: function Update(){ If (Input.GetKey(KeyCode.F2));{Application.Loadlevel("level2");} else if (Input.GetKey(KeyCode.F3)){ Application.Loadlevel("level3");} else if (Input.GetKey(KeyCode.F4)){ Application.Loadlevel("level4");} else if (Input.GetKey(KeyCode.F5)){ Application.Loadlevel("level5");} } but what I get is this error: Assets/NewBehaviourScript.js(3,63): BCE0044: expecting :, found ';'. what's wrong there? i think i almost got it, grr :)

Jul 27 '10 at 10:06 PM ama

I typed a bit too fast, and without spellchecking :/. The first "If" statement has an uppercase I, it should be "if". That's the only error I can see there, but bare in mind that I am just waking up :)

Jul 28 '10 at 04:14 AM Thaelvyn
(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:

x379
x322
x166

asked: Jul 27 '10 at 02:51 PM

Seen: 1725 times

Last Updated: Aug 08 '12 at 03:06 AM