Book Image

Unity Game Development Scripting

By : Kyle D'Aoust
Book Image

Unity Game Development Scripting

By: Kyle D'Aoust

Overview of this book

Table of Contents (17 chapters)
Unity Game Development Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating levels


In the game, there will be three playable levels and a main menu. The main menu will have three buttons on it: one to play the game, one for options, and a final one to exit the game.

The main menu

Create a new scene and name it Main Menu. Next, drag the Audio_Config, Video_Config, and Config_GUI scripts to the main camera. These will be used for our Options menu. Next, create a new C# script, name it MainMenu, and add this code to it:

void OnGUI()
{
  if(GetComponent<Config_GUI>().optionsGUI == false)
  {
    if(GUI.Button(new Rect(700, 400, 150, 50), "Play Game"))
      Application.LoadLevel("Chapter 10_a");
    if(GUI.Button(new Rect(700, 475, 150, 50), "Options"))
      GetComponent<Config_GUI>().optionsGUI = true;
    if(GUI.Button(new Rect(700, 550, 150, 50), "Quit Game"))
      Application.Quit();
  }
    
  GetComponent<Config_GUI>().OnGUI();
}

For this script, all that you will need is the OnGUI function. This code will create a few buttons that will...