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:
Back in
MonoDevelop
in theLevelEditor
class, we're going to want to first add in anOnGUI
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(); }
Next, inside our
GameController
class, add the following code to ourUpdate
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...