- Home /
Better control over the GUI components?
Hello,
I use this code to change the size of a grid with the GUI Controls
fGridSize = GUI.HorizontalSlider(new Rect(5,20,200-10,20),fGridSize,0.2f,1f);
The Problem is that its using all float values between 0.2f and 1f, But I want it in steps like 0.1f. How can I do that? I also dont understand what the "value" parameter is for of the horizontalslider, because the return value already indicates the slider value.
Any ideas?
Comment
Best Answer
Answer by robertbu · May 21, 2013 at 02:43 AM
The value parameter tells HorizontalSlider() where to place the slider. The slider does not remember the position from previous frames. Which is why you can use it to solve the problem you are trying to solve. For your "tab-like" behavior you can do this:
var fGridSize = 0.6;
function OnGUI() {
fGridSize = GUI.HorizontalSlider(new Rect(5,20,200-10,20),fGridSize,0.2f,1f);
fGridSize = Mathf.Round(fGridSize * 10.0) / 10.0;
}