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

Unlock the full course today

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

Player movement class

Player movement class - Unity Tutorial

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

Start my 1-month free trial

Player movement class

- [Voiceover] Now it's time for us to lay out the foundation that'll allow us to move our player around the map. But thinking ahead, let's try to abstract out the logic we need to move around the map into a self-contained class. We're gonna create a new C# script called MapMovementController. Now let's open this up in MonoDevelop. Here, we can delete the Start and Update methods. Now let's create a public field to store a reference to the map itself. We'll do public, type it to Map class, and call it map. Next, we'll need a vector to store the tile size so we know how to do the calculations as we're moving things around in the map. We'll create a public Vector2 tileSize field. And finally we'll need two fields to represent an x- and y- position we can reuse as we calculate the position. We'll make this private int tmpX and private int tmpY. Now let's create a new public method with a return type of void called MoveTo. Here, we're gonna pass in the index to the tile we wanna move to…

Contents