void Update() { if (!_menuController.StopMove) { Vector2 characterPosition = VectorTransformer.Vector3ToVector2(transform.position); if (Input.GetAxis("Horizontal") > 0.5f & _movingDirection == Direction.None & ValidatePosition(characterPosition.y)) { _movingDirection = Direction.Right; _velocity = new Vector2(1 * walkSpeed, 0); _isMoving = true; } else if (Input.GetAxis("Horizontal") < -0.5f & _movingDirection == Direction.None & ValidatePosition(characterPosition.y)) { _movingDirection = Direction.Left; _velocity = new Vector2(-1 * walkSpeed, 0); _isMoving = true; } else if (Input.GetAxis("Vertical") > 0.5f & _movingDirection == Direction.None & ValidatePosition(characterPosition.x)) { _movingDirection = Direction.Up; _velocity = new Vector2(0, 1 * walkSpeed); _isMoving = true; } else if (Input.GetAxis("Vertical") < -0.5f & _movingDirection == Direction.None & ValidatePosition(characterPosition.x)) { _movingDirection = Direction.Down; _velocity = new Vector2(0, -1 * walkSpeed); _isMoving = true; } else if (_isMoving) { switch (_movingDirection) { case Direction.Right: _target = new Vector2(Mathf.RoundToInt(characterPosition.x + 1f), Mathf.RoundToInt(characterPosition.y)); break; case Direction.Left: _target = new Vector2(Mathf.RoundToInt(characterPosition.x - 1f), Mathf.RoundToInt(characterPosition.y)); break; case Direction.Up: _target = new Vector2(Mathf.RoundToInt(characterPosition.x), Mathf.RoundToInt(characterPosition.y + 1f)); break; case Direction.Down: _target = new Vector2(Mathf.RoundToInt(characterPosition.x), Mathf.RoundToInt(characterPosition.y - 1f)); break; } _isMoving = false; } else if (!characterPosition.Equals(_target)) { float distance = Mathf.Abs(characterPosition.x - _target.x) + Mathf.Abs(characterPosition.y - _target.y); if (distance < 0.2) { transform.position = _target; _velocity = new Vector2(0, 0); _movingDirection = Direction.None; } } _rigidbody.velocity = _velocity; } }