Author Topic: How do I make UISlider value go beyond 0to1?  (Read 6758 times)

Zenneth

  • Guest
How do I make UISlider value go beyond 0to1?
« 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.

Khalos

  • Guest
Re: How do I make UISlider value go beyond 0to1?
« Reply #1 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do I make UISlider value go beyond 0to1?
« Reply #2 on: May 28, 2013, 02:43:21 PM »
float yourVal = Mathf.Lerp(min, max, slider.sliderValue);

Zenneth

  • Guest
Re: How do I make UISlider value go beyond 0to1?
« Reply #3 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do I make UISlider value go beyond 0to1?
« Reply #4 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.