Game Development Reference
In-Depth Information
3.
Add the following variable:
public GUISkin newSkin; // custom skin to use
Block in the OnGUI function:
4.
void OnGUI () {
GUI.skin = newSkin;
// Constrain all drawing to be within a 600x600 pixel area
GUI.BeginGroup (new Rect (Screen.width / 2 - 300, Screen.height /
2 - 350, 600, 600));
// must match all BeginGroup calls with an EndGroup
GUI.EndGroup ();
}
Inside the GUI.Group , add the controls code:
5.
// Draw a box in the new coordinate space defined by the BeginGroup.
GUI.Box (new Rect (0,0,600,600),"Main Menu");
int y = 60; // base Y position
int x = 60; // base x inset
int yOffset = 60; // y offset
// Play Game
if (GUI.Button( new Rect (x,y,200,40), "Play / Resume")) {
// start game
Screen.showCursor = false; // hide the cursor
Application.LoadLevel("GardenLevel1");
}
y+= yOffset;
// Settings
if (GUI.Button( new Rect (x,y,200,40), "Settings")) {
// go to settings menu
Application.LoadLevel("SettingsMenu");
}
y+= yOffset;
// Quit
if (GUI.Button( new Rect (x,y,200,40), "Credits")) {
// got to credits
Application.LoadLevel(3);
}
y+= yOffset;
// Quit
if (GUI.Button( new Rect (x,y,200,40), "Quit")) {
// quit application
Application.Quit();
}
Search WWH ::




Custom Search