Book Image

Unity Game Development Blueprints

By : John P. Doran
Book Image

Unity Game Development Blueprints

By: John P. Doran

Overview of this book

Table of Contents (16 chapters)
Unity Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Level editor – toggling editor, GUI, and selecting additional tiles


Now that we have the basic functionality in, it wouldn't be that enjoyable if all we could do was add and remove walls. We also want to be able to spawn collectibles and change the player's starting location. Let's work on that next:

  1. Back in MonoDevelop in the LevelEditor class, we're going to want to first add in an OnGUI function to display the types of things we can create:

    void OnGUI()
    {
      GUILayout.BeginArea(new Rect(Screen.width - 110, 20, 100, 800));
      foreach(Transform item in tiles)
      {
        if (GUILayout.Button (item.name))
        {
          toCreate = item;
          
        }
      }
      GUILayout.EndArea();
    }
  2. Next, inside our GameController class, add the following code to our Update function (create the function as well if it doesn't exist in your current implementation, such as the example code):

    void Update()
    {
      if(Input.GetKeyDown("f2"))
      {
        this.gameObject.GetComponent<LevelEditor>().enabled = true;
      }
    }

    Now, if we...