- Home /
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
Answer by Thaelvyn · Jul 27, 2010 at 03:02 PM
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") }
}
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? :)
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 :)
You missed a few semi colons, you need : Application.Loadlevel("level2");
hi there, thank u very much for your help. so i entered this code onto an empty GameObject: function Update(){ If (Input.Get$$anonymous$$ey($$anonymous$$eyCode.F2));{Application.Loadlevel("level2");} else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.F3)){ Application.Loadlevel("level3");} else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.F4)){ Application.Loadlevel("level4");} else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.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 :)
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 $$anonymous$$d that I am just waking up :)
Your answer
Follow this Question
Related Questions
Click Object to change scene 2 Answers
just a simple question.. 1 Answer
Is it possible to change keyboard input inGame 1 Answer
Change level after destroying all enemies? 1 Answer
Chage level Whith time 1 Answer