OnGUI sliders only accept float? C#

Hi.

I’d like to make an integer (‘int’) based GUI slider, similar to EditorGUI.IntSlider, running inside the game. I’ve tried GUI.HorizontalSlider, but it only allows for ‘float’. How could I do that?

Thanks.

Just round it to “int” with Mathf.RoundToInt. EditorGUI.IntSlider does exactly the same thing :wink:

int val = 0;

val = Mathf.RoundToInt(GUILayout.HorizontalSlider(val, 0, 10));
// or
val = Mathf.RoundToInt(GUI.HorizontalSlider(yourRect, val, 0, 10));

yourValue = (int)GUI.HorizontalSlider(Rect yourRect, yourvalue, 2,25);
you can cast your slider output to int instead of using the Mathf class