Search Unity

Smooth slider bars

Discussion in 'Animation' started by Toharawk, Dec 19, 2018.

  1. Toharawk

    Toharawk

    Joined:
    Aug 26, 2017
    Posts:
    6
    Hi there,

    I was wondering if there is a way in unity to make the slider bars more smoother while changing the value of it? If so, can it be managed with a c# script or is a animation for the slider required?

    Looking forward to replies! ,)
    Toharawk
     
  2. Define "smoother", what's the problem with it? Are we talking about UI?
     
  3. Toharawk

    Toharawk

    Joined:
    Aug 26, 2017
    Posts:
    6
    Thanks for the fast reply LurkingNinjaDev!

    I am talking about a regular UI Slider. The idea is, to edit the value of the slider more "smooth" as soon as it changes. Current situation:

    EXP_Bar (slider) get +10.00f. -> The slider change the value from 0 to 10.00f immediately, within a frame.
    It would be fantastic, if it would be possible to slow down the "add value process", so the Exp_Bar (slider) display the addition within 2-3 seconds, and not immediately - to create a smooth addition effect. I hope i've explained it understandable enough ,)
     
  4. You will need to write a script for that. Basically Lerping between the two values over time. Check out the Lerp function, maybe Coroutine if you want the UI to stay responsive during the smoothing.
    - Basically you will need to create a state of "adjusting" or something and in update while you're adjusting you can change the slider's value towards the target value. If you reach it, you stop the state.
    - Write a coroutine which gets the final value and on every frame you adjust the slider value a little bit then yield.

    There is no built-in function to animate the slider this way AFAIK.
     
    Toharawk likes this.