Game Development Reference
In-Depth Information
The Slider/Scrollbar controls
When you need to control a range in your games. GUI or add a handle to control
moving properties between two values, like moving an object around in your scene,
this is where the Slider and Scrollbar controls come in. They provide two similar
out-of-the-box implementations that give a scrollable region and a handle to control
the value behind the control.
Here, they are presented side by side:
The slimmer Slider and chunkier Scrollbar controls can both work in either
horizontal or vertical modes and have presets for the minimum and maximum
values allowed.
Slider control code
In code, the Slider control code is represented as follows:
private float fltSliderValue = 0.5f;
void OnGUI() {
fltSliderValue = GUI.HorizontalSlider(new Rect(25, 250, 100,30),
fltSliderValue, 0.0f, 10.0f);
fltSliderValue = GUI.VerticalSlider(new Rect(150, 250, 25, 50),
fltSliderValue, 10.0f, 0.0f);
}
Scrollbar control code
In code, the Scrollbar control code is represented as follows:
private float fltScrollerValue = 0.5f;
void OnGUI() {
fltScrollerValue = GUI.HorizontalScrollbar(new Rect(25, 285,
100, 30), fltScrollerValue, 1.0f, 0.0f, 10.0f);
fltScrollerValue = GUI.VerticalScrollbar(new Rect(200, 250, 25,
50), fltScrollerValue, 1.0f, 10.0f, 0.0f);
}
 
Search WWH ::




Custom Search