예제 #1
0
    private void Update()
    {
        if (fov.EnemyVisible() && !dead)
        {
            if (!playingEnemySpottedSound)
            {
                if (enemySpottedSoundStopped)
                {
                    enemySpottedAudioSource.Play();
                    enemySpottedSoundStopped = false;
                }
                enemySpottedAudioSource.volume = 0;
                enemySpottedTime0        = Time.time;
                playingEnemySpottedSound = true;
            }
            enemySpottedAudioSource.volume = Mathf.Min(1.0f, (Time.time - enemySpottedTime0) / enemySpottedAttack);
        }
        else if (playingEnemySpottedSound)
        {
            playingEnemySpottedSound = false;
            enemySpottedTime0        = Time.time;
        }
        else
        {
            enemySpottedAudioSource.volume = Mathf.Max(0.0f, 1.0f - ((Time.time - enemySpottedTime0) / enemySpottedDecay));
            if (enemySpottedAudioSource.volume == 0.0f)
            {
                enemySpottedAudioSource.Stop();
                enemySpottedSoundStopped = true;
            }
        }
        foreach (char c in Input.inputString)
        {
            if (c == 'n')
            {
                if (cheatcode == "kelvi")
                {
                    godMode = !godMode;
                }
                cheatcode = "";
            }
            else
            {
                cheatcode += c;
            }
        }
        if (Input.inputString == "kelvin")
        {
            Debug.Log("godMode");
            godMode = !godMode;
        }

        if (!godMode && HP <= 0)
        {
            enemySpottedAudioSource.volume = 0;
            enemySpottedAudioSource.Stop();
            if (!dead)
            {
                GameObject musicObject = GameObject.FindGameObjectWithTag("music");
                if (musicObject != null)
                {
                    musicObject.GetComponent <AudioSource>().Stop();
                }
                deathAudioSource.PlayOneShot(DeathSound);
                deathDelayTimer = DeathSound.length;
                dead            = true;
            }
            hud.die();
            deathDelayTimer -= Time.deltaTime;
            if (deathDelayTimer <= 0)
            {
                enemySpottedAudioSource.volume = 1;
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
            }
        }
    }