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.

Track player movement on tiles

Track player movement on tiles - Unity Tutorial

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

Start my 1-month free trial

Track player movement on tiles

- [Voiceover] Now that we're moving our player around the map, we're gonna want to get events that let us know when the player lands on a tile, and what that tile type is. To do this, let's go into our Scripts folder and open up our map movement controller. At the top of our class, we're going to add a new public delegate. Its return type will be void, and we're going to call this TileAction. And inside of this we'll pass in an int for the tile type, which we'll get from the auto tile ID. Next, let's create a new public field below this that's typed to our tile action, and, we'll call this tileActionCallback. Now, in order for this to work, we're going to fire this event when the player lands on a tile. The first place we're going to do this is in the move to method. Let's look for the condition where we test if animate equals false, and set the transformed opposition to the new position. Since this gets triggered immediately when the player moves to this tile, let's do a condition to…

Contents