2DShooter Part3

By Eric Haines (a.k.a. Eric5h5)

Adding the object to the level editor
To make the object show up in the level editor, first make sure the LevelEditor scene in the Levels folder is loaded. Click on the Main Camera object in the Hierarchy, which is what the scripts are attached to. In the Level Editor script section in the Inspector, open the Tile Materials arrow to expose all the materials that are available for the different tiles, and change the Size element from 11 to 12. Now drag your enemy material from the Project view to element 11 in the list (since numbering starts at 0). Find the Editor GUI script in the Inspector (you might have to scroll down), and open the Icons arrow, which shows the icons that you can select in the level editor. You'll notice there are more materials than icons, which is because the wall icon actually represents a collection of 8 different tiles that are automatically drawn by the editor, depending on the tile's neighbors. Change the Size element to 5, and drag the enemy texture (not the material) from the Project view onto element 4.

That's it; you can now press Play to run the editor, and your enemy will show up as the fifth icon. You can load or draw a level, and then place the enemies wherever you want. You'll notice it's not to scale (assuming you reduced the size of your enemy), which is because the tiles are all drawn with the same tile object, rather than using the enemy prefab you made. This is just cosmetic and won't affect the actual level when played. When done, save the level. The level file is saved in the root folder of the project; in order for it to load in the game, copy it to the TextAssets folder in the 2DShooter Assets folder. The advantage to having a level file be a TextAsset is that it will automatically be bundled in with your game when you build it.

If you want, you can customize the editor in a number of ways by changing the public variables in the two scripts. For the Level Editor script, Scroll Speed, Zoom Speed, and Drag Speed all affect how fast scrolling within the editor is. Scroll area is how many pixels from the edge it takes to trigger the screen scrolling. The rest affect the default level: Top Border and Side Border is how many solid tiles there are surrounding the editable area, and Level Size W is the default editable width, with Level Size L naturally being the editable length. For the Editor GUI script, Icon Size is how big the icons are in pixels, with Inset being the number of pixels from the edge of the screen the windows are set.

2D Shooter Index : Previous Part : Next Part