Exemplo n.º 1
0
 public RigitMovementManager(Rigidbody2D rigidbody, BoxCollider2D collisionBox, Animator animator)
 {
     _rigidbody = rigidbody;
     _collisionBox = collisionBox;
     _animator = animator;
     _currentMovement = RigitMovement.None;
 }
Exemplo n.º 2
0
    /// <summary>
    /// Updates movement acording to input.
    /// </summary>
    public void UpdateMovement()
    {
        float horizontalInput = Input.GetAxis(Constants.Input_Horizontal);
        RigitMovement previousMovement = _currentMovement;

        if (Mathf.Abs(horizontalInput) > Constants.Threshold)
        {
            if (horizontalInput > 0)
            {
                _rigidbody.transform.Translate(Vector3.right * Mathf.Abs(horizontalInput) * Time.deltaTime * MovementSpeed);
                _currentMovement = RigitMovement.PositiveX;
            }
            else
            {
                _rigidbody.transform.Translate(Vector3.left * Mathf.Abs(horizontalInput) * Time.deltaTime * MovementSpeed);
                _currentMovement = RigitMovement.NegativeX;
            }
        }
        else _currentMovement = RigitMovement.None;

        if (!previousMovement.Equals(_currentMovement)) if (MovementChanged != null) MovementChanged(_currentMovement, previousMovement);
    }