示例#1
0
    void Movement()
    {
        Vector2 anymove = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

        if (!Input.GetKey(KeyCode.LeftShift))
        {
            if (Input.GetAxisRaw("Vertical") > 0.1)
            {
                controller.Move(transform.forward * walkSpeedV * Time.deltaTime);
            }
            if (Input.GetAxisRaw("Vertical") < -0.1)
            {
                controller.Move(transform.forward * -walkSpeedV * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.2f);
            }
            if (Input.GetAxisRaw("Horizontal") < -0.1)
            {
                controller.Move(transform.right * -walkSpeedH * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.6f);
            }
            if (Input.GetAxisRaw("Horizontal") > 0.1)
            {
                controller.Move(transform.right * walkSpeedH * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.4f);
            }
        }
        if (Input.GetKey(KeyCode.LeftShift) && sBar.getCurrentStamValue < stamDrain)
        {
            if (Input.GetAxisRaw("Vertical") > 0.1)
            {
                controller.Move(transform.forward * walkSpeedV * Time.deltaTime);
            }
            if (Input.GetAxisRaw("Vertical") < -0.1)
            {
                controller.Move(transform.forward * -walkSpeedV * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.2f);
            }
            if (Input.GetAxisRaw("Horizontal") < -0.1)
            {
                controller.Move(transform.right * -walkSpeedH * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.6f);
            }
            if (Input.GetAxisRaw("Horizontal") > 0.1)
            {
                controller.Move(transform.right * walkSpeedH * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.4f);
            }
        }
        else if (Input.GetKey(KeyCode.LeftShift) && sBar.getCurrentStamValue >= stamDrain)
        {
            if (Input.GetAxisRaw("Vertical") > 0.1)
            {
                controller.Move(transform.forward * runSpeedV * Time.deltaTime);
            }
            if (Input.GetAxisRaw("Vertical") < -0.1)
            {
                controller.Move(transform.forward * -runSpeedV * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.2f);
            }
            if (Input.GetAxisRaw("Horizontal") < -0.1)
            {
                controller.Move(transform.right * -runSpeedH * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.6f);
            }
            if (Input.GetAxisRaw("Horizontal") > 0.1)
            {
                controller.Move(transform.right * runSpeedH * Time.deltaTime);
                anim.SetFloat("StrafeDir", 0.4f);
            }

            //drain stam on run


            if (anymove != Vector2.zero && Input.GetKey(KeyCode.LeftShift) && !drainingStam)
            {
                StartCoroutine(RunningDrain());
            }
            IEnumerator RunningDrain()
            {
                drainingStam = true;
                sBar.SetStam(sBar.getCurrentStamValue - stamDrain);
                yield return(new WaitForSeconds(1));

                drainingStam = false;
            }
        }



        Vector2 inputMove = new Vector2(Input.GetAxis("Vertical"), Input.GetAxis("Horizontal"));

        if (inputMove.x > 0.1)
        {
            anim.SetFloat("SpeedPercent", 0.5f);
        }
        if (Input.GetKey(KeyCode.LeftShift) && sBar.getCurrentStamValue >= stamDrain && inputMove.x > 0.1)
        {
            anim.SetFloat("SpeedPercent", 1f);
        }

        if (inputMove.x == 0)
        {
            anim.SetFloat("SpeedPercent", 0);
        }
        if (inputMove.y == 0 && inputMove.x >= 0)
        {
            anim.SetFloat("StrafeDir", 0f);
        }
    }