コード例 #1
0
    // IEnumerator IncreaseTime()
    // {
    //     float t = 0.05f;
    //     while (t < 1)
    //     {
    //         t += Time.unscaledDeltaTime;
    //         Time.timeScale = t;
    //         yield return null;
    //     }
    //     Time.timeScale = 1;
    // }

    void Update()
    {
        //GODMODE
        if (Input.GetKeyDown("l") && !godMode)
        {
            godMode = true;
        }
        else if (Input.GetKeyDown("l") && godMode)
        {
            godMode = false;
        }

        if (godMode)
        {
            uiBar.UpdateHp(100);
            uiBar.DecreaseBreath(-10);
            UpdateAether(1);
        }

        if (!calculated)
        {
            StartCoroutine(WaitToUpdate());
        }
        //Cooldowns
        if (airCd > 0)
        {
            airCd -= Time.deltaTime;
        }
        if (dashCd > 0)
        {
            dashCd -= Time.deltaTime;
        }

        if (Input.GetButtonUp("MouseWheel") && menu.activeInHierarchy)
        {
            menu.SetActive(false);
            Time.timeScale      = 1;
            Time.fixedDeltaTime = .02f;
            Cursor.lockState    = CursorLockMode.Locked;
            // Cursor.visible = true;
            SetElement(selectedAbility);
            SetState(State.Moving);
            fireball.isCharging = false;
            aetherBurst.Play();
            StartCoroutine(IncreaseSphereCollider());
        }
        if (Input.GetButtonDown("MouseWheel") && burstTime == -1)
        {
            menu.SetActive(true);
            GetComponentInChildren <Projector>().enabled = false;
            Time.timeScale      = .05f;
            Time.fixedDeltaTime = Time.timeScale * .05f;
            movement           /= 10;
            pos = Input.mousePosition;
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible   = false;
            SetState(State.ChangingElements);
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        if (Input.GetMouseButtonUp(1))
        {
            rightMouseUp = true;
        }
        if (Input.GetMouseButtonDown(1))
        {
            rightMouseUp = false;
        }

        if (Input.GetButtonDown(Tab))
        {
            targetlock    = !targetlock;
            targetanalyse = true;
        }

        HandleTarget();

        switch (state)
        {
        case State.Moving:

            if (Input.GetKey(KeyCode.Backspace) && bouldertrigger != null)
            {
                transform.position = bouldertrigger.position;
            }

            movement = new Vector3(Input.GetAxis(Horizontal), 0f, Input.GetAxis(Vertical)).normalized;
            animator.SetFloat("Vx", movement.x);
            animator.SetFloat("Vy", movement.z);
            // magnitude = Mathf.Lerp(magnitude, movement.sqrMagnitude, Time.deltaTime * 2);
            Vector3 v = new Vector3(rbdg.velocity.x, 0f, rbdg.velocity.z);
            magnitude = Mathf.Lerp(magnitude, v.sqrMagnitude / 70, Time.deltaTime * 7);
            if (magnitude > 1)
            {
                magnitude = 1;
            }
            animator.SetFloat("Velocity", magnitude);

            if (Input.GetButtonDown(RightClick) && !uiBar.isChanging)
            {
                HandleAbilities();
            }
            if (Input.GetButtonUp(RightClick) && currentAbility == waterEffect)
            {
                GetComponentInChildren <Projector>().enabled = false;
                StartCoroutine(waterEffect.GetComponent <WaterElement>().CastWaterPrison());
                animator.SetTrigger("WaterStun");
                StartCoroutine(Cast(2.5f, 10f));
                UpdateAether(-1);
            }

            //No mouse wheel button?
            if (Input.GetKey("1"))
            {
                SetElement(airEffect);
            }
            if (Input.GetKey("2"))
            {
                SetElement(fireEffect);
            }
            if (Input.GetKey("3"))
            {
                SetElement(waterEffect);
            }

            if (Input.GetKeyDown("n"))
            {
                SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1);
            }
            else if (Input.GetKeyDown("m"))
            {
                SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex - 1);
            }

            //MOBILITY
            if (Input.GetButtonDown(Jump) && !uiBar.isChanging)
            {
                if (isGrounded)
                {
                    // playerMovement.Jump();

                    if (magnitude > 0.05)
                    {
                        animator.SetTrigger("RunningJump");
                    }
                    else
                    {
                        animator.SetTrigger("Jump");
                    }

                    hasJumped = true;
                }
                else
                {
                    pressedJump = true;
                    StartCoroutine(WaitSomeFrames());
                }
            }

            if (Input.GetButton("LeftShift") && !uiBar.isChanging)
            {
                if (uiBar.GetBreathValue() > 17 && dashCd <= 0)
                {
                    if (!targetlock || tmpInput.z < -.9f)
                    {
                        animator.SetTrigger("RunningDash");
                        // if (isGrounded) animator.SetTrigger("RunningDash");
                        // else animator.SetTrigger("FallingDash");
                        // playerMovement.Dash(transform.forward);
                    }
                    else
                    {
                        Vector3 dirToEnemy = (enemy.transform.position - transform.position).normalized;
                        playerMovement.Dash((transform.forward + dirToEnemy).normalized);
                    }

                    dashCd = 1.5f;
                }
            }
            tmpInput = movement;

            TargetsAndBoulders();

            movement.y = 0;

            AnimatorStateInfo currentState = animator.GetCurrentAnimatorStateInfo(0);
            if (movement != Vector3.zero)
            {
                transform.rotation = Quaternion.LookRotation(movement);
                // if (!currentState.IsName("Jumping") && rbdg.velocity.y == 0)
                if (isGrounded)
                {
                    if (!currentState.IsName("AriRunning") && !targetlock)
                    {
                        animator.SetBool("Running", true);
                    }
                    else if (targetlock && !currentState.IsName("TLTree"))
                    {
                        animator.SetBool("TargetLocked", true);
                    }
                }
            }
            else
            if (currentState.IsName("AriRunning") && !stopping)
            {
                animator.SetBool("Running", false);
            }


            if (Input.GetButtonDown(Jump) && !isGrounded && hasJumped && uiBar.GetBreathValue() > 18 && !uiBar.isChanging && !playerMovement.isTouching)
            {
                animator.SetTrigger("DoubleJump");
                // playerMovement.DoubleJump(new Vector3(movement.x, 1f, movement.z));
                hasJumped = false;
            }

            break;

        case State.Idle:
            Time.fixedDeltaTime = .02f;
            Time.timeScale      = 1f;
            animator.SetBool("Running", false);
            break;

        case State.Talking:
            // TargetsAndBoulders();
            break;

        case State.ChangingElements:
            ElementMenu();

            break;


        case State.Charging:
            movement = new Vector3(Input.GetAxisRaw(Horizontal), 0f, Input.GetAxisRaw(Vertical)).normalized / 100;
            // if (movement != Vector3.zero) transform.rotation = Quaternion.LookRotation(movement);
            break;

        default:
            break;
        }
    }