/// <summary> /// Function that reads the input from the user and moves the player accordingly /// </summary> private void MovePlayer() { rb.velocity = new Vector2(horizontalMovement * moveSpeed, rb.velocity.y); if (horizontalMovement < 0) { facing = playerFacing.Left; } else if (horizontalMovement == 0) { // nothing happens } else { facing = playerFacing.Right; } }
/// <summary> /// Handles the facing of the player to the direction that the player is moving in, only changes when the player swaps movement directions /// </summary> private void FacePlayer() { if (facing != lastFacing) { switch (facing) { case playerFacing.Right: { transform.localScale = new Vector3(1, 1, 1); Debug.Log("|PLAYERMOVEMENT| ===> The player is now moving to the right, flipping sprite"); break; } case playerFacing.Left: { transform.localScale = new Vector3(-1, 1, 1); Debug.Log("|PLAYERMOVEMENT| ===> The player is now moving to the left, flipping sprite"); break; } } lastFacing = facing; } }
// Start is called before the first frame update void Start() { facing = playerFacing.Right; lastFacing = facing; rb = GetComponent <Rigidbody2D>(); }