Book Image

Building an FPS Game with Unity

5 (1)
Book Image

Building an FPS Game with Unity

5 (1)

Overview of this book

Table of Contents (18 chapters)
Building an FPS Game with Unity
Credits
Foreword
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a main menu: part 3 – button functionality


Now that we have the buttons in the scene, let's make it such that, when we click on them, they will both start and quit the games, respectively.

Our buttons need to have some functionality on clicking them, but we need to provide a function for them to call to go to another level. Let's create a new object with a new component that we will use to do this.

  1. Go to GameObject | Create Empty. Rename our newly created object to MainMenuEvents.

  2. From the Project tab, open up the MyGame/Scripts folder and then select Create | C# Script and call it MainMenuEvents.

  3. Double-click on the script to bring it into MonoDevelop. Once opened, replace what is there with the following code:

    using UnityEngine;
    using System.Collections;
    
    public class MainMenuEvents : MonoBehaviour 
    {
    
      public void LoadGameLevel(string level)
      {
        Application.LoadLevel(level);
      }
    
      public void QuitGame()
      {
        print ("Quit Game");
        Application.Quit();
      }
    }

    This class contains...