Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Zenneth on May 28, 2013, 10:11:14 AM

Title: How do I make UISlider value go beyond 0to1?
Post by: Zenneth on May 28, 2013, 10:11:14 AM
How do I make UISlider value go beyond 0 to 1?
To be more precise, I need it to range between -1 to 2.
Title: Re: How do I make UISlider value go beyond 0to1?
Post by: Khalos on May 28, 2013, 01:38:12 PM
Multiply the value of the slider by 3, and then subtract 1.

So:

  1. float adjustedSliderValue = (slider.sliderValue * 3) - 1;

Just to show a few cases:

(0 * 3) - 1 = -1
(0.5 * 3) - 1 = 0.5
(1 * 3) - 1 = 2
Title: Re: How do I make UISlider value go beyond 0to1?
Post by: ArenMook on May 28, 2013, 02:43:21 PM
float yourVal = Mathf.Lerp(min, max, slider.sliderValue);
Title: Re: How do I make UISlider value go beyond 0to1?
Post by: Zenneth on May 29, 2013, 09:38:35 AM
I think I should re-phrase this, I want the slider image to go toward the left when the value is negative, and go to the right when positive.

By this point, I cannot get the UISlider to go to the negative side.

gaugePhy.sliderValue = -2f;      
print (gaugePhy.sliderValue);

I tried to debug with direct number, but when I checked the value, it got clamped to 0-1 value.

What is the variable that I need to adjust in order for the image to expand toward the left side?
Title: Re: How do I make UISlider value go beyond 0to1?
Post by: ArenMook on May 29, 2013, 12:19:35 PM
You can't do that with the built-in slider. You need to write your own component for this.