Book Image

Unity 5.x Game Development Blueprints

By : John P. Doran
Book Image

Unity 5.x Game Development Blueprints

By: John P. Doran

Overview of this book

<p>This book will help you to create exciting and interactive games from scratch with the Unity game development platform. We will build 7-8 action-packed games of different difficulty levels, and we’ll show you how to leverage the intuitive workflow tools and state of the art Unity rendering engine to build and deploy mobile desktop as well as console games.</p> <p>Through this book, you’ll develop a complete skillset with the Unity toolset. Using the powerful C# language, we’ll create game-specific characters and game environments. Each project will focus on key Unity features as well as game strategy development. This book is the ideal guide to help your transition from an application developer to a full-fledged Unity game developer</p>
Table of Contents (19 chapters)
Unity 5.x Game Development Blueprints
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Level editor – adding/removing walls at runtime


Now that our level editor will be able to load in this data, we now want to have a way to actually modify what we see onscreen. To do this, we'll need to create a GUI interface and functionality for our level editor.

  1. The first thing we need to do is add a variable to keep track of what item we want to spawn:

    // The object we are currently looking to spawn
    private Transform toCreate;
  2. Now, we need to initialize this variable inside our Start function:

    toCreate = tiles[0];
  3. Next, we need to update our Update function and then explain how it's working, as follows:

        void Update()
        {
            // Left click - Create object
            if (Input.GetMouseButton(0) && GUIUtility.hotControl == 0)
            {
                Vector3 mousePos = Input.mousePosition;
    
    /*
    Set the position in the z axis to the
    opposite of the camera's so that the position is on the world so ScreenToWorldPoint will give us valid
    values.
    */
                mousePos.z = Camera.main.transform...