コード例 #1
0
    //Check the currentState of the player.
    void CheckStates()
    {
        switch (currentState)
        {
        case PlayerState.Idle:
            playerAnim.SetAnimState(AnimationState.Idle);
            inputDirection = Vector3.zero;
            break;

        case PlayerState.Walk:
            playerAnim.SetAnimState(AnimationState.Walk);
            MoveSpeed.initialValue = 2;
            break;

        case PlayerState.Run:
            playerAnim.SetAnimState(AnimationState.Run);
            break;

        case PlayerState.Attack:
            playerAnim.SetAnimState(AnimationState.SwordAttack);
            SwordMomentumScale.initialValue += SwordMomentumSmooth * Time.deltaTime;
            SwordMomentum = Mathf.Lerp(SwordMomentumPower, 0, SwordMomentumScale.initialValue);

            //Check if there's an input, otherwise move in the anim's direction.
            if (inputDirection != Vector3.zero)
            {
                position = (SwordMomentum * inputDirection);
            }
            else
            {
                position = (SwordMomentum * direction.initialPos);
            }

            break;

        case PlayerState.Paused:
            rb.bodyType = RigidbodyType2D.Static;
            playerAnim.AnimPause(true);
            Invincible = true;                     //Invincible while paused
            break;

        case PlayerState.Hitstun:
            position = Vector3.zero;
            playerAnim.AnimPause(true);
            break;

        default:
            currentState = PlayerState.Idle;
            break;
        }

        //CurrentState special checks
        //IF not paused
        if (currentState != PlayerState.Paused)
        {
            rb.bodyType = RigidbodyType2D.Dynamic;
            playerAnim.AnimPause(false);
        }

        //If not walk
        if (currentState != PlayerState.Walk)
        {
            MoveSpeed.initialValue = 4;
        }

        //Set Idle
        if (currentState != PlayerState.Attack && currentState != PlayerState.Paused && currentState != PlayerState.Hitstun)
        {
            if (position == Vector3.zero)
            {
                currentState = PlayerState.Idle;
            }
        }
    }