From the course: Unity 5: 2D Movement in an RPG Game

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Visit tiles

Visit tiles - Unity Tutorial

From the course: Unity 5: 2D Movement in an RPG Game

Start my 1-month free trial

Visit tiles

- [Voiceover] And now it's time for us to trigger what happens when we visit a tile. Let's go into our RandomMapTester, and scroll to the bottom of the class. Here, we're gonna add a new method with a return type of void and we're gonna call it VisitTile. Here we'll pass in an int for the index of the tile that we're visiting. Inside of this method, we're gonna want to get a reference to the tile that we're looking at. Here we're gonna create a new variable for tile and we're gonna set it equal to the map.tiles array index. Then we're gonna look at the tile.visited value and set it to true. Next, we're gonna want to repaint the tile by calling DecorateTile and passing in the index. Now this'll work great for a single tile but we also want to make sure that we update all the tiles around it. To do this, we're gonna need to create a foreach loop and inside of this foreach loop, we'll create a variable called neighbor in tile.neighbors. Which returns all of the neighboring tiles for the…

Contents