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

Get Building an FPS Game with Unity now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.