官术网_书友最值得收藏!

Adding a structure to our levels

Open the Run & Jump project and look for the folder Scripts/Level. Inside this folder, you will find all the related to the video game. The Level class is responsible for making our levels work.

As you may have noticed, in Chapter 1, Getting Started with Editor Scripting, all the level piece prefabs are added to the scene and used by the level without a problem, but we don't have control over the size of the level or any way to guarantee that the level piece prefabs are going to be in the right position. Most important, the Level class is not aware about the level piece prefabs present on the level.

We are going to fix this situation making changes to the Level class, adding an array to save references to the level piece prefabs and define it size based in the total columns and rows supported by that array.

Visually, you are going to see the size of the level with the help of a grid made with gizmos.

As this chapter requires changes on the Level class, there a couple of things you must know:

  • The Level class is a partial class, this means that its content is divided in several files: the Level.cs and Level.Logic.cs scripts. This is just to make its manipulation easier in the book. All the changes will take place in Level.cs.
  • The Level class follows a Singleton design pattern, this means that the instantiation of the class is restricted to just one object and you can have access to this from any other class using the Level.Instance method.

    Note

主站蜘蛛池模板: 太仆寺旗| 专栏| 和龙市| 泾阳县| 平遥县| 文安县| 西丰县| 景宁| 萨嘎县| 施秉县| 宝清县| 通化县| 青龙| 老河口市| 耿马| 隆昌县| 霍林郭勒市| 迁安市| 石嘴山市| 卓尼县| 长岛县| 平乡县| 资源县| 宝鸡市| 东乌珠穆沁旗| 郧西县| 基隆市| 鹤山市| 谢通门县| 万全县| 龙游县| 淮阳县| 平凉市| 德钦县| 新平| 迁西县| 宁武县| 永安市| 翁源县| 南靖县| 漠河县|