From the course: Unity 5: 2D Movement in an RPG Game
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Detect the tile to move to - Unity Tutorial
From the course: Unity 5: 2D Movement in an RPG Game
Detect the tile to move to
- [Voiceover] Now it's time for us to figure out the actual tile that we need to move to. In order to do this, we're gonna want to pass a direction to the MapMovementController. Let's open up this class and add in the logic. To start, we're gonna create a new public field that is typed to int, and we'll call this currentTile. Next, we'll need a private field to store an int for tmpIndex. We'll use both of these values in order to figure out where the player currently is and where the player needs to move to. First, in the MoveTo method, we're gonna wanna store a value to the current tile. Next, let's set the value of currentTile to equal the index that's passed into the MoveTo method. Now below the MoveTo method, let's create a new public method with a return type of void called MoveInDirection. Here we'll supply a Vector2 called dir for direction so that we know how to manipulate the X and Y value of the currentTile. To do this, we're gonna need to calculate that value first, so…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.