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; } ...