Adding enemies to the world board
As usual, we will need to generate the enemies at random to keep the player on their toes. We then need to address the issue of enemies being able to move through black space. We will also have to handle the event that an enemy moves off screen.
Let's start by adding the enemies to the world board. Open up the BoardManager.cs
script for editing. You can start by adding the line public GameObject enemy;
under all the other public variables. This will be our Enemy prefab reference. Then, take a look at Code Snip 7.2 for the rest of the update:
1 private void addTiles(Vector2 tileToAdd) { 2 if (!gridPositions.ContainsKey (tileToAdd)) { 3 gridPositions.Add (tileToAdd, tileToAdd); 4 GameObject toInstantiate = floorTiles [Random.Range (0, floorTiles.Length)]; 5 GameObject instance = Instantiate (toInstantiate, new Vector3 (tileToAdd.x, tileToAdd.y, 0f), Quaternion.identity) as GameObject; 6 instance.transform.SetParent (boardHolder); 7 8 if (Random...