Author Topic: Limit slider max value?  (Read 2927 times)

drewradley

  • Guest
Limit slider max value?
« on: September 20, 2013, 04:15:30 PM »
If, for instance, I want to stop the slider at .7 and allow it to slide no further, how can I accomplish this? I currently use (just a place holder to test)
  1. i=slider.sliderValue;
  2. if i > .7
  3. {
  4. slider.sliderValue=.7f
  5. }

And it does prevent it from going any higher than .7f but instead of just stopping and not moving any further, it drops back to 0 if I try to slide it beyond .7f. I need it to stay where it is unless they drag it back down.

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Limit slider max value?
« Reply #1 on: September 20, 2013, 04:49:45 PM »
Don't try to do that. Instead do this:
  1. float yourCappedValue = Mathf.Lerp(0f, 0.7f, slider.sliderValue);

drewradley

  • Guest
Re: Limit slider max value?
« Reply #2 on: September 20, 2013, 05:12:16 PM »
Thanks for your help however, I am uncertain how to implement that. I understand what it does but have no idea how to make it work. Everything I've tried either keeps the slider locked at 0 or slides back down to zero when I let go. It does, however, stop nicely at .7f.

never mind. got it. It was so simple. Put it and set the slider value to capped value in my if statement. Sometimes I'm a little slow on the uptick.

Thanks!
« Last Edit: September 20, 2013, 05:19:39 PM by drewradley »