x


Can't slide horizontal slider

Hello,

I tried to make a horizontal slider (with C#). But when I run the game. I can't move the slider.

Anyone knows why that is? Code below:

float hSliderValue = 5.0f;

OnGUI {
Rect slider = new Rect (50, 30, 100, 30);
GUI.HorizontalSlider(slider,hSliderValue,1.0f,100.0f);
}
more ▼

asked Mar 30 '10 at 11:43 AM

user-1836 (google) gravatar image

user-1836 (google)
33 2 2 5

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

3 answers: sort voted first

Hi, HorizontalSlider returns a value.

static function HorizontalSlider (position : Rect, value : float, leftValue : float, rightValue : float) : float

this should work:

float hSliderValue = 5.0f;

void OnGUI() {
      Rect slider = new Rect (50, 30, 100, 30);
      hSliderValue  = GUI.HorizontalSlider(slider,hSliderValue,1.0f,100.0f);
}
more ▼

answered Mar 30 '10 at 12:14 PM

Lloyd Hooson gravatar image

Lloyd Hooson
67 1 1 6

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

You need to feed the return value back into your variable:

float hSliderValue = 5.0f;

OnGUI {
    Rect slider = new Rect (50, 30, 100, 30);
    hSliderValue = GUI.HorizontalSlider(slider,hSliderValue,1.0f,100.0f);
}

A lot of the GUI controls work that way.

more ▼

answered Mar 30 '10 at 12:14 PM

runevision gravatar image

runevision ♦♦
8.1k 29 46 112

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

thnx .. worked for me .. was having the same problem

more ▼

answered Nov 23 '12 at 07:12 AM

parjanyaroy gravatar image

parjanyaroy
16 2

(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:

x3699
x19

asked: Mar 30 '10 at 11:43 AM

Seen: 2872 times

Last Updated: Nov 23 '12 at 07:12 AM