void LateUpdate() { var velocity = _rigidbody2D.velocity.normalized; float speedx = velocity.x; float speedy = velocity.y; _facingDir = GetFacingDir(speedx, speedy); if (_facingDir == _lastFacingDir) { return; } _lastFacingDir = _facingDir; SetAnimatorAccordingToDirection(_facingDir); HandleLeftRight(speedx); }
private void SetAnimatorAccordingToDirection(CharacterDirections facingDir) { switch (facingDir) { case CharacterDirections.Top: _animator.Play("Top"); break; case CharacterDirections.Bottom: _animator.Play("Bottom"); break; case CharacterDirections.Left: _animator.Play("Side"); break; case CharacterDirections.Right: _animator.Play("Side"); break; default: throw new ArgumentOutOfRangeException("facingDir", facingDir, null); } }