Game Development Reference
In-Depth Information
To create sample horizontal and vertical sliders, in MonoDevelop edit the GUIToggleAndSliders
script's code as follows:
#pragma strict
var toggle : boolean = false;
var horizSlider : float = 0.0;
var vertSlider : float = 0.0;
function OnGUI () {
toggle = GUI.Toggle (Rect (Screen.width - 100, Screen.height - 100, 100, 30), toggle,
"Toggle switch");
Debug.Log(toggle);
horizSlider = GUI.HorizontalSlider (Rect (Screen.width/2, 25, 100, 30), horizSlider, 0.0, 10.0);
Debug.Log(horizSlider);
vertSlider = GUI.VerticalSlider (Rect (Screen.width/2, 50, 100, 30), vertSlider, 0.0, 10.0);
Debug.Log(vertSlider);
}
This breaks down as follows:
(1) var horizSlider : float = 0.0;
var vertSlider : float = 0.0;
1.
Declare a float type variable to hold the position of the horizontal and vertical
slider knobs.
(2) horizSlider = GUI.HorizontalSlider (Rect (Screen.width/2, 25, 100, 30),
horizSlider, 0.0, 10.0);
2.
The float horizSlider will be assigned the new position of the slider and
redraw the slider accordingly with each frame. The pattern here is: position,
size, current value of the slider, minimum value, and maximum value.
(3) Debug.Log(horizSlider);
3.
Log the horizontal slider value to the Console.
(4) vertSlider = GUI.VerticalSlider (Rect (Screen.width/2, 50, 100, 30),
vertSlider, 0.0, 10.0);
4.
The vertical slider takes the same parameters as the horizontal slider,
following the pattern of: position, size, current value of the slider, minimum
value, and maximum value.
(5) Debug.Log(vertSlider);
5.
Log the vertical slider value to the Console.
Search WWH ::




Custom Search