Book Image

Unity 2D Game Development Cookbook

By : Claudio Scolastici
Book Image

Unity 2D Game Development Cookbook

By: Claudio Scolastici

Overview of this book

<p>Unity is a powerful game development engine that provides rich functionalities to create 2D and 3D games.</p> <p>Unity 2D Game Development Cookbook is a practical guide to creating games with Unity. The book aims to serve the purpose of exploring problematic concepts in Unity for 2D game development, offering over 50 recipes that are easy to understand and to implement, thanks to the step-by-step explanations and the custom assets provided. The practical recipes provided in the book show clearly and concisely how to do things right in Unity. By the end of this book, you'll be near "experts" when dealing with Unity. You will also understand how to resolve issues and be able to comfortably offer solutions for 2D game development.</p>
Table of Contents (15 chapters)
Unity 2D Game Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The game manager


To create the game manager functionality, we need a script to initialize a new scene and the state manager. We also need a second scene to be added to our project, to switch between scenes (named Home and Game). Another script is required to create a button that sends the application from the home scene to the game scene. Finally, we need a game object to attach the scripts to, which we are preserving as we switch between scenes. Let's get to work!

Getting ready

Open your project in Unity. We begin by adding a new script to the Scripts folder.

How to do it...

  1. Access the Scripts folder in the Project panel and create a new C# script. Name the script StateManager.

  2. Double-click on the file to open it in Monodevelop.

  3. Add the following lines to the script:

      using UnityEngine;
      using System.Collections;
      public class StateManager : MonoBehaviour {
        private static StateManager instance
        public static StateManager Instance
        {
          get
          {
            if(instance == null)
    ...