Is there anyway to make set values for a slider that when slid it will snap to those values? For example say I have a slider with a value of 0 to 10. Can I have 10 values in-between so when you slide it, it snaps to 1 then 2 then 3, ect. Instead of being able to freely slide it to whatever value you want.
Here’s a versatile piece of code to round to any interval. You can include this in a function that gets called when the slider’s value is changed.
float value = slider.value; float interval = 0.2f; //any interval you want to round to value = Mathf.Round(value / interval) * interval; slider.value = value;
You could cast the result of .Slider to an int, which would lock it to integers. Or you could go more fancy and write your own locking code -
int result = GUI.Slider(blah);
if ( result < 10 ) result = 0; else if ( result < 20 ) result = 10;