Exemplo n.º 1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }


        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (_timeCounter > 0)
            {
                _runCounter = true;
            }
        }

        if (Input.GetKeyDown(KeyCode.O))
        {
            audiosource.PlayOneShot(audiosource.clip);
        }


        // FIKSE KNAPPER
        if (Input.GetKeyDown(KeyCode.Minus))
        {
            _timeCounter -= 10;

            if (GameHasRunOnce == false)
            {
                startTime = _timeCounter;
            }
        }

        if (Input.GetKeyDown(KeyCode.Plus))
        {
            _timeCounter += 10;

            if (GameHasRunOnce == false)
            {
                startTime = _timeCounter;
            }
        }

        int min = Mathf.FloorToInt(_timeCounter / 60);
        int sec = Mathf.FloorToInt(_timeCounter % 60);

        TimerText.text = min.ToString("00") + ":" + sec.ToString("00");

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


        if (_runCounter)
        {
            GameHasRunOnce = true;
            HeartAnimator.SetBool("runbeat", true);



            _timeCounter -= Time.deltaTime;

            if (_timeCounter <= 0)
            {
                _timeCounter   = 0;
                TimerText.text = "00:00";
                _runCounter    = false;
                audiosource.PlayOneShot(audiosource.clip);
                skiftpladser.SetActive(true);
                HeartAnimator.Stop();

                SliderGO.gameObject.SetActive(false);
                TimerText.gameObject.SetActive(false);
            }

            if (_timeCounter <= 11 && _timeCounter > 0)
            {
                TextAnimation.SetTrigger("panic");
                TimerText.color = Color.red;
            }



            SliderGO.value = (startTime - _timeCounter) / startTime;
        }
    }