O'Reilly logo

Unity Game Development Blueprints by John P. Doran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Level editor – saving/loading levels to file

Now that we have the groundwork all placed and ready, let's get to the real meat of the level editor: saving and loading! Perform the following steps:

  1. Open our LevelEditor class in MonoDevelop. The first step will be to include some additional functionality at the beginning of our file:
    //You must include these namespaces
    //to use BinaryFormatter
    using System;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.IO;
  2. The first thing we'll want to add is a variable, as follows:
    string levelName = "Level1";
  3. Now, we'll need to add the following code to the OnGUI function:
    GUILayout.BeginArea(new Rect(10, 20, 100, 100)); levelName = GUILayout.TextField(levelName); if (GUILayout.Button ("Save")) { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required