Esempio n. 1
0
    void Update()
    {
        if (Input.GetKey("escape"))
        {
            // exit on escape
            SceneManager.UnloadScene(SceneManager.GetActiveScene().name);
            SceneManager.LoadScene("MainMenu");
        }


        waveTimer += Time.deltaTime; //Adds to total time in the wave

        for (int i = 0; i < activeLumberjacks.Count; i++)
        {
            EnemyScript es = activeLumberjacks[i];

            if (es.dead)
            {
                activeLumberjacks.RemoveAt(i);
                i--;
            }
            else if (es.CanApplyDamage())
            {
                treeHp -= es.damage;
                es.ResetDamageTimer();
            }
        }

        float treeHpPercent    = treeHp / maxTreeHp;
        float remainingPercent = 1 - treeHpPercent;

        treeHpText.text           = ((int)(treeHpPercent * 100)) + "%";
        RenderSettings.fogDensity = 0.1f * remainingPercent;
        Color skyColor = new Color(blueSkyColor.r + ((redSkyColor.r - blueSkyColor.r) * remainingPercent),
                                   blueSkyColor.g + ((redSkyColor.g - blueSkyColor.g) * remainingPercent),
                                   blueSkyColor.b + ((redSkyColor.b - blueSkyColor.b) * remainingPercent));

        Camera.main.backgroundColor = skyColor;

        if (treeHp <= 0)
        {
            //You lost the game ;(
        }
        else if (activeLumberjacks.Count == 0 && toSpawn.Count == 0)
        {
            if (waveNumber == 10)
            {
                //You won! :D
            }
            else
            {
                //Need to spawn another wave
                PopulateWave(++waveNumber);
            }
        }

        if (toSpawn.Count > 0 && (int)waveTimer > lastSpawn)
        {
            lastSpawn = (int)waveTimer;
            SpawnLumberjack();
        }

        enemiesLeftText.text = (activeLumberjacks.Count + toSpawn.Count).ToString();
    }