Search Unity

Moving a Slider with specific increments, is it possible?

Discussion in 'General Discussion' started by Razputin, Nov 10, 2022.

  1. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    356
    Is there anyway to move a slider with specific increments, what I mean by that is take a slider for example that goes 0-1. When the player drags it, it can land on any float between 0-1. However I'd like the slider to snap to specific values when dragged. So instead of any value 0-1, it would go 0, 0.25, 0.5, 0.75, 1.

    Hope that makes sense,
    Thanks!
     
  2. shakirashalesh123

    shakirashalesh123

    Joined:
    Nov 10, 2022
    Posts:
    1

    Can you share the code you are using for this kind of slider.
     
    Last edited: Nov 11, 2022
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    Use "WholeNumbers" property.

    https://docs.unity3d.com/ru/2018.4/ScriptReference/UI.Slider-wholeNumbers.html
     
    Razputin likes this.
  4. Razputin

    Razputin

    Joined:
    Mar 31, 2013
    Posts:
    356
    neginfinity likes this.