Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        // Set the horizontal movement for the character based on user input
        Vector2 moveInput = new Vector2(GetHorizontalMovement(), GetVerticalMovement());

        if (!DashAttackAction.IsActive)
        {
            MvCon.Input = moveInput;
        }
        else
        {
            MvCon.Input = new Vector2();
        }

        // Update dash activation
        bool dashInput = UpdateAction(ref DashAttackAction, GetDashInput());

        if (dashInput && moveInput.magnitude > 0.5f && DashesLeft > 0)
        {
            DashAttackAction.IsActive = true;
            DashTimeSpent             = 0.0f;
            DashDirection             = moveInput.normalized;
            --DashesLeft;
        }
        // Regen dashes
        if (MvCon.IsGrounded && !DashAttackAction.IsActive)
        {
            DashesLeft = MaxDashes;
        }

        // Update audio state
        if (MvCon.IsGrounded && !DashAttackAction.IsActive)
        {
            if (moveInput.magnitude > 0.5f && !ChAu.GetMoving())
            {
                ChAu.SetMoving(true);
            }
            else if (moveInput.magnitude < 0.5f && ChAu.GetMoving())
            {
                ChAu.SetMoving(false);
            }
        }
        else
        {
            ChAu.SetMoving(false);
        }

        // Update animation state
        if (DashAttackAction.IsActive)
        {
            if (IsRecoilActive)
            {
                ChSpr.SetFrame(4);
            }
            else
            {
                ChSpr.SetFrame(3);
            }
            ChSpr.SetFacing(DashDirection.x >= 0.0f);
        }
        else if (!MvCon.IsGrounded)
        {
            ChSpr.SetFrame(5);
        }
        else if (!Mathf.Approximately(moveInput.x, 0.0f))
        {
            ChSpr.SetFrame(0);
            ChSpr.SetFacing(moveInput.x >= 0.0f);
        }
        else
        {
            ChSpr.SetFrame(1);
        }
    }