O'Reilly logo

Building an FPS Game with Unity by John P. Doran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required