Game Development Reference
In-Depth Information
6.
Add the following variables:
float diffSliderValue = 5.0f; // difficulty slider
float ambSliderValue = 1.0f; // ambient volume slider
7.
In the OnGUI function, clear the contents of the GUI Group as follows:
void OnGUI () {
GUI.skin = newSkin;
// Constrain all drawing to be within a 600 x 600 pixel area centered
on the screen.
GUI.BeginGroup (new Rect (Screen.width / 2 - 300, Screen.height /
2 - 350, 600, 600));
// must match all BeginGroup calls with an EndGroup
GUI.EndGroup ();
}
This code is pretty standard. You are once again creating a group and visualizing its size and
location with a Box. You will also be using variables again to make tweaking the control element's
layout easier to refine.
8.
Add the controls inside the GUI Group:
// Draw a box in the new coordinate space defined by the BeginGroup.
GUI.Box (new Rect (0,0,600,600),"Settings");
int y = 240; // base Y position
int x = 200; // base x inset
int yOffset = 60; // y offset
// difficulty slider
GUI.Label(new Rect (x - 50, y, 300, 60), "Difficulty");
y+= yOffset;
diffSliderValue = GUI.HorizontalSlider (new Rect (x, y, 200, 60),
diffSliderValue, 10.0f, 0f);
y+= yOffset;
// ambient volume slider
GUI.Label(new Rect (x - 50, y, 300, 60), "Ambient Sound Volume");
y+= yOffset;
ambSliderValue = GUI.HorizontalSlider (new Rect (x, y, 200, 60),
ambSliderValue, 0.0f, 1.0f);
if (GUI.Button( new Rect (156200,y + 40,200,40), "Main Menu")) {
// Back to Main Menu
Application.LoadLevel("MainMenu"1);
}
 
Search WWH ::




Custom Search