Book Image

Extending Unity with Editor Scripting

Book Image

Extending Unity with Editor Scripting

Overview of this book

Table of Contents (18 chapters)
Extending Unity with Editor Scripting
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Upgrading the Level class


In this video game, a level is just a Unity scene with several level piece prefabs aligned with each other. When we started this project, we took a look at how the level scenes were implemented and found that there was no relation between these prefabs and the Level class through code.

In the last chapter, we added gizmos to display a grid and the necessary methods to make game objects snap to this grid. Now, the focus is to make the Level class capable of knowing what is on the level scene.

To the Level class, we will add an array to handle a 2D matrix of LevelPieces, the base class of the level piece prefabs in Run & Jump. Its size will be determined explicitly by two variables, that is, the total number of columns and rows in the grid.

Go to the Scripts/Level folder and open the Level.cs script. Add the following code to the class:

[SerializeField]
private LevelPiece[] _pieces;

public LevelPiece[] Pieces {
get { return _pieces; }
   set {_pieces = value; }
...