コード例 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //camera setting: get the direction camera is facing.
        Vector3 camDir = PlayerCamera.transform.forward;

        camDir.y = 0;
        camDir.Normalize();

        Vector3 newVel = Vector3.zero;

        if (PM)
        {
            if (Input.GetAxis(DashButton) == 1 && GetComponent <PlayerStamina>().currentStamina > 50)
            {
                myStats.setCharging(true);
                IsCharging = Input.GetAxis(DashButton);
                animate.SetFloat("IsCharging", IsCharging);
            }

            if (Input.GetAxis(DashButton) != 1 && myStats.isCharging() && GetComponent <PlayerStamina>().currentStamina > 50)
            {
                newVel  = Vector3.zero;
                dashDir = camDir;
                myStats.setCharging(false);
                myStats.setDashing(true);


                IsDashing = true;
                animate.SetBool("IsDashing", IsDashing);

                GetComponent <PlayerStamina>().ApplyFatigue(50);
            }
        }

        if (myStats.isCharging() == true)
        {
            transform.rotation = Quaternion.LookRotation(camDir);
        }

        //if (PM.isDashing()) {
        if (myStats.isDashing())
        {
            dashRecovery++;
            newVel             += dashDir * (speed * 3f);
            transform.position += (newVel * Time.fixedDeltaTime);

            //transform camera
            if (newVel != Vector3.zero)
            {
                transform.rotation = Quaternion.LookRotation(dashDir);
            }

            //check if dash is over
            if (dashRecovery >= dashDuration)
            {
                myStats.setDashing(false);
                dashRecovery = 0;
                IsDashing    = false;
                animate.SetBool("IsDashing", IsDashing);
                IsCharging = 0.0f;
                animate.SetFloat("IsCharging", IsCharging);
            }
        }
    }