Adding character facing directions

The last task we have is to add a functionality that will allow the player to change the direction he or she faces. Then, we can add some functionality that will allow the sword to swing in the same direction that the player is facing. To achieve this, we will have to start in the MovingObject class.

The AttempMove function is where the direction of the player is managed. This is where we can poll what direction the player is moving in, and change the sprite direction accordingly. Code snip 6.9 shows the update that should be added to the top of the AttemptMove function definition:

1 protected virtual bool AttemptMove <T> (int xDir, int yDir) 2 where T : Component 3 { 4 if (xDir == 1) { 5 transform.eulerAngles ...

Get Procedural Content Generation for Unity Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.