- Home /
Adjusting a GUI slider with the arrow keys? c#
Hi all, I am trying not to use the mouse in my game. My question: Is there any way I can adjust the value of a GUI slider using the left/right arrow keys?
My code:
 void OnGUI () 
     {
         if(PauseGame.pause==true)
         {    
             
             
             hSliderValue = GUI.HorizontalSlider(new Rect(25F, 25F, 600F, 30F), hSliderValue, 0.0F, 10.0F);
 
 
                 if(GUI.Button(new Rect(25,60,600,20), "Press When Finished")) 
                 {
                     
                     
                     PauseGame.pause = false;
                     Time.timeScale = 1;
                 return;
                 }
         }
         else if(Time.timeScale ==1){
         update();
         }
     
     }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by psychlab1 · May 18, 2012 at 11:40 PM
Alright, figured it out
 void OnGUI () 
 {
     if(PauseGame.pause==true)
     {    
         if(Input.GetKey("left"))
         {
             hSliderValue = hSliderValue -0.1F;
         }
         else if(Input.GetKey("right"))
         {
             hSliderValue = hSliderValue+0.1F;    
         }
         
         hSliderValue = GUI.HorizontalSlider(new Rect(25F, 25F, 600F, 30F), hSliderValue, 0.0F, 10.0F);
             if(GUI.Button(new Rect(25,60,600,20), "Press When Finished")) 
             {
                 
                 
                 PauseGame.pause = false;
                 Time.timeScale = 1;
             return;
             }
     }
     else if(Time.timeScale ==1){
     update();
     }
 
 }
@psychlab1 It is recommended to use http://unity3d.com/support/documentation/ScriptReference/Event.html>Event inside of GUI ins$$anonymous$$d of Input
@hijinxbassist thanks, i see that Event doesn't support Get$$anonymous$$ey, can you tell me the syntax I would need? is it just Event("left")?
Your answer
 
 
             Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Horizontal Slider Won't Move 1 Answer
iTween & gesture 0 Answers
Can I use the new GUI system with instantiated prefabs? 1 Answer
