slider bar in inspector

I have searched for a while and can’t seem to find a simple answer to this.

I want to have a variable controlled by a slider bar.

So I give it limits and away it goes.

Is this simply or difficult? do I need to write a custom editor object for this? or is there a way to state ‘display this float as a sliding bar’?



[Range(0.0f, 10.0f)]

public float mySliderFloat;


@Range (0.0, 10.0)

var mySliderFloat;


[Range(0.0F, 10.0F)]

public mySliderFloat as float = 0.0F

That’s decorating the field declaration for the scipt.

I think it was added for Unity 4

If you already have a custom editor attached to the gameobject where you’d like a slider, then adding the [Range(min,max)] decorator will not work. You’ll need to use EditorGUILayout.Slider(value, min, max) inside of your OnInspectorGUI method.

Range[minalue, maxValue]

is a slider able to have a spot where it sticks? i have a slider that goes between 0f and 2f, and i’d like it to snap to 1f. is that possible without a custom editor?

You need to write a custom editor and use one of the EditorGUI slider functions.