- Home /
 
 
               Question by 
               Evil Tebor · Apr 06, 2010 at 09:03 PM · 
                inputtriggerenablekey  
              
 
              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
};
 
                
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Peter G · Apr 06, 2010 at 09:37 PM
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*/);
        } 
    }   
}
 
              Your answer