- Home /
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'?
Thanks
Answer by RobinWatson77777 · Jun 10, 2014 at 08:09 AM
---C#---
[Range(0.0f, 10.0f)]
public float mySliderFloat;
---JS---
@Range (0.0, 10.0)
var mySliderFloat;
---Boo---
[Range(0.0F, 10.0F)]
public mySliderFloat as float = 0.0F
That's decorating the field declaration for the scipt.
http://docs.unity3d.com/ScriptReference/PropertyDrawer.html
I think it was added for Unity 4
You're missing two f's in the c# range code, otherwise it's working like a charm...thank you!
Is it possible to change this to the accepted answer? It's clearly the right one.
Answer by aressler · Nov 15, 2016 at 08:50 AM
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.
Answer by Eric5h5 · May 30, 2015 at 02:47 AM
You need to write a custom editor and use one of the EditorGUI slider functions.
Your answer
Follow this Question
Related Questions
Array has length 0, but I can see its' elements in the inspector 1 Answer
Restrict sliders in Unity inspector to have different values 1 Answer
Sliding GUI.HorizontalSlider also moves Camera with FreeCamera script 0 Answers
Inspector slider value? 2 Answers
Move camera with inspector slider and include it's current location? 2 Answers