Пример #1
0
    // Use this for initialization
    void Start()
    {
        oxygen  = max0xygen;
        lives   = maxLives;
        display = GetComponent <PlayerHeartDisplay>();
        display.OnChangeHeart(maxLives, lives);
        display.OnChangeOxygen((int)oxygen);
        oxygenCounter = liveLossTime;

        invisibilityCounter = 0;
        flashCounter        = flashLength;

        audioSource = GetComponent <AudioSource>();
        controller  = GetComponent <PlayerController>();
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (invisibilityCounter > 0)
        {
            invisibilityCounter -= Time.deltaTime;
            flashCounter        -= Time.deltaTime;
            if (flashCounter <= 0)
            {
                playerRenderer.enabled = !playerRenderer.enabled;
                flashCounter           = flashLength;
            }

            if (invisibilityCounter <= 0)
            {
                playerRenderer.enabled = true;
            }
        }

        if (regenOxygen)
        {
            if (oxygen < max0xygen)
            {
                if (!audioSource.isPlaying)
                {
                    audioSource.PlayOneShot(oxygenRegen);
                }
                oxygen += oxygenIncreaseRate * Time.deltaTime;
            }
        }
        else
        {
            if (oxygen > 0)
            {
                oxygen -= oxygenDecreaseRate * Time.deltaTime;
            }

            // Audio warnings
            if (oxygen > 50 && oxygen < 51 && !audioSource.isPlaying)
            {
                audioSource.PlayOneShot(oxygen50);
            }
            if (oxygen > 25 && oxygen < 26 && !audioSource.isPlaying)
            {
                audioSource.PlayOneShot(oxygen25);
            }
            if (oxygen > 10 && oxygen < 11 && !audioSource.isPlaying)
            {
                audioSource.PlayOneShot(oxygen10);
            }
        }

        if (oxygen <= 0)
        {
            oxygenCounter -= Time.deltaTime;
        }

        if (oxygenCounter <= 0)
        {
            TakeDamage(1, new Vector3(0, 0, 0));
            oxygenCounter = liveLossTime;
        }

        display.OnChangeOxygen((int)oxygen);
    }