Beispiel #1
0
    void Update()
    {
        //To mitigate snap when switching camera
        Vector3 forwardCam = Vector3.ProjectOnPlane(playerCam.forward, Vector3.up).normalized;

        if (shmupMode)
        {
            if (!preForwardCam.Equals(Vector3.zero) && velocity.x != 0 && velocity.z != 0)
            {
                preMoving = true;
            }
            else
            {
                preMoving = false;
            }
        }
        else
        {
            preMoving = false;
        }

        inputH = Input.GetAxis("Horizontal");
        inputV = Input.GetAxis("Vertical");
        if (!_controller.isGrounded && doubleJump < 1)
        {
            jump = false;
        }
        if (Input.GetButtonDown("Jump"))
        {
            jump = true;
        }
        if (Input.GetButtonDown("Sprint"))
        {
            // if(!sprint) {
            //     moveSpeed *= 2;
            //     sprint = true;
            // }
            // else {
            //     sprint = false;
            //     moveSpeed /= 2;
            // }
            if (dashCharges > 0)
            {
                if (dashCharges == 2)
                {
                    dashChargeUI2.sizeDelta = new Vector2(0, dashChargeUI2.sizeDelta.y);
                    dashChargeUI2.GetComponent <Image>().color = new Color32(0, 76, 86, 255);
                }
                else if (dashCharges == 1)
                {
                    dashChargeUI1.sizeDelta = new Vector2(0, dashChargeUI1.sizeDelta.y);
                    dashChargeUI1.GetComponent <Image>().color = new Color32(0, 76, 86, 255);
                }

                Vector3 movDir;
                Vector3 adjustedVelocity = new Vector3(_controller.velocity.x, 0, _controller.velocity.z);
                if (adjustedVelocity.magnitude > 0)
                {
                    movDir = _controller.velocity.normalized;
                }
                else
                {
                    movDir = playerCam.forward.normalized;
                }
                movDir.y = 0;
                _controller.Move(movDir * 5);
                dashCharges -= 1;
                dashing      = true;
            }
        }

        if (_controller.isGrounded)
        {
            dashing = false;
        }

        if (dashCharges < 2 && !dashing)
        {
            dashCool += Time.deltaTime;
            if (dashCharges == 0)
            {
                if (dashCool < DASH_COOLDOWN)
                {
                    dashChargeUI1.sizeDelta = new Vector2((dashCool / DASH_COOLDOWN) * 45, dashChargeUI1.sizeDelta.y);
                    dashChargeUI2.sizeDelta = new Vector2(0, dashChargeUI2.sizeDelta.y);
                }
                else
                {
                    dashChargeUI1.sizeDelta = new Vector2(45, dashChargeUI1.sizeDelta.y);
                    dashChargeUI2.sizeDelta = new Vector2((dashCool - DASH_COOLDOWN / (DASH_COOLDOWN)) * (45), dashChargeUI2.sizeDelta.y);
                }

                if (dashCool >= DASH_COOLDOWN * 2)
                {
                    dashChargeUI2.sizeDelta = new Vector2(45, dashChargeUI2.sizeDelta.y);
                    dashChargeUI2.GetComponent <Image>().color = new Color32(0, 229, 255, 255);
                    dashChargeUI1.GetComponent <Image>().color = new Color32(0, 229, 255, 255);
                    dashCool    -= DASH_COOLDOWN * 2;
                    dashCharges += 2;
                }
            }
            else if (dashCool >= DASH_COOLDOWN)
            {
                dashChargeUI2.GetComponent <Image>().color = new Color32(0, 229, 255, 255);
                dashCool    -= DASH_COOLDOWN;
                dashCharges += 1;
            }
            if (dashCharges == 1)
            {
                dashChargeUI2.sizeDelta = new Vector2((dashCool / DASH_COOLDOWN) * 45, dashChargeUI2.sizeDelta.y);
            }
        }
        shmupDir.x = Input.GetAxis("Mouse X_");
        shmupDir.z = Input.GetAxis("Mouse Y_");
        playerHealth.heal(Time.deltaTime);
    }