Graphics Reference
In-Depth Information
case 2:
GUI.BeginGroup (new Rect (default_width / 2 - 150,
default_height / 2 - 250, 500, 500));
// Are you sure you want to exit?
GUI.Label(new Rect(0, 50, 300, 50), "Are you sure
you want to exit?", "textarea");
if(GUI.Button(new Rect(0, 250, 300, 40),"YES, QUIT
PLEASE!"))
{
ExitGame();
}
if(GUI.Button(new Rect(0, 300, 300, 40),"NO, DON'T
QUIT"))
{
GoMainMenu();
}
GUI.EndGroup ();
break;
The audio options menu is a little different from the ones we've seen so far in this
chapter, as it calls for two horizontal sliders to set the sound effect and music volume levels:
case 3:
// AUDIO OPTIONS
GUI.BeginGroup (new Rect (default_width / 2 - 150,
default_height / 2 - 250, 500, 500));
GUI.Label(new Rect(0, 50, 300, 50), "AUDIO OPTIONS",
"textarea");
GUI.Label(new Rect(0, 170, 300, 20), "SFX volume:");
After setting up the group and rendering two labels, we move on to the code to render
the horizontal slider, which looks like this:
audioSFXSliderValue = GUI.HorizontalSlider (new Rect( 0, 200, 300, 50 ),
audioSFXSliderValue, 0.0f, 1f);
Here, we set the audioSFXSliderValue variable (a float) to the return value that the GUI.
HorizontalSlider gives back. A slider may take up to five parameters as follows:
1. A rectangle defining the size of the area the slider will take up.
2. The current value at which to render the slider handle. The audioSFXSliderValue
variable is used here, and it's OK for the GUI.HorizontalSlider to send feedback
to itself, as we set audioSFXSliderValue to the return value of the slider and at the
same time set the value of the handle to the same variable.
3. The value at the left end of the slider. Your slider can start anywhere, but in this
case, we need it to start at 0.
Search WWH ::




Custom Search