Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Building an FPS Game with Unity

You're reading from  Building an FPS Game with Unity

Product type Book
Published in Oct 2015
Publisher
ISBN-13 9781782174806
Pages 326 pages
Edition 1st Edition
Languages

Table of Contents (18) Chapters

Building an FPS Game with Unity
Credits
Foreword
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started on an FPS 2. Building Custom Weapons 3. Prototyping Levels with Prototype 4. Creating Exterior Environments 5. Building Encounters 6. Breathing Life into Levels 7. Adding Polish with ProBuilder 8. Creating a Custom GUI 9. Finalizing Our Project 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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}