x


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();
       }

    }
more ▼

asked May 18 '12 at 10:13 PM

psychlab1 gravatar image

psychlab1
1 1 2

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

1 answer: sort voted first

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();
    }

}
more ▼

answered May 18 '12 at 11:40 PM

psychlab1 gravatar image

psychlab1
1 1 2

@psychlab1 It is recommended to use Event inside of GUI instead of Input

May 18 '12 at 11:48 PM hijinxbassist

@hijinxbassist thanks, i see that Event doesn't support GetKey, can you tell me the syntax I would need? is it just Event("left")?

May 19 '12 at 12:16 AM psychlab1
(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:

x3694
x224
x103

asked: May 18 '12 at 10:13 PM

Seen: 490 times

Last Updated: May 19 '12 at 12:16 AM