x


Trigger enabling keys

At the moment I have a trigger to make a menu pop up saying that the person won the level. Then i want them to be able to press a key to conitnue to the next level. However I'm not really sure how to do it.

I currently have:

function OnGUI () {   
 GUI.skin = mySkin;
if (triggerEnd == true)     
GUI.Label (Rect (Screen.height-300, Screen.height-125, 200, 100), "Fortress Annihilated!", "TextField"); 
//insert key code here
};
more ▼

asked Apr 06 '10 at 09:03 PM

Evil Tebor gravatar image

Evil Tebor
63 6 7 14

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

1 answer: sort voted first

Your code looks good. Add braces after your if statement to enclose the GUI and the part you are about to add. After the GUI.Label(). Add:

if(Input.GetKeyDown(KeyCode.Space)) {
Application.LoadLevel(/*Next Level*/);
}

So your whole code will look like this.

function OnGUI () {   
    GUI.skin = mySkin;
    if (triggerEnd == true) {     
        GUI.Label (Rect (Screen.height-300, Screen.height-125, 200, 100), "Fortress Annihilated!", "TextField");
        if(Input.GetKeyDown(KeyCode.Space)) {
            Application.LoadLevel(/*Next Level*/);
        } 
    }   
}
more ▼

answered Apr 06 '10 at 09:37 PM

Peter G gravatar image

Peter G
15k 16 44 136

Thank you very much. Worked perfectly :D

Apr 06 '10 at 09:51 PM Evil Tebor
(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:

x986
x956
x166
x135

asked: Apr 06 '10 at 09:03 PM

Seen: 1046 times

Last Updated: Apr 06 '10 at 09:28 PM