Пример #1
0
    // Update is called once per frame
    void Update()
    {
        //New Wave starts
        if (waveActionTick != null && waveActionTick.IsAction())
        {
            waveDurationActionTick = new ActionTick(WaveDuration, false);
            spawnEnemyActionTick   = new ActionTick(1000, true);
            waveDurationActionTick.IsAction(); //First call starts thread
            waveActionTick = null;

            WaveDisplay.Find("Text").GetComponent <Text>().text = "Wave " + Wave + " starts ...";
            WaveDisplay.gameObject.SetActive(true);
        }

        //Disable wave display after 3 seconds
        if (waveDurationActionTick != null && waveDurationActionTick.TimeToNextTick < WaveDuration - 3000 &&
            WaveDisplay.gameObject.activeInHierarchy)
        {
            WaveDisplay.gameObject.SetActive(false);
        }


        //Execute enemy spawning during wave
        if (waveDurationActionTick != null && spawnEnemyActionTick != null &&
            waveDurationActionTick.IsRunning() && spawnEnemyActionTick.IsAction())
        {
            System.Random r = new System.Random();
            spawnEnemyActionTick = new ActionTick(r.Next(4000, 8000), false);

            SpawnEnemy(r.Next(0, 5));
        }

        //Wave ends
        if (waveDurationActionTick != null && !waveDurationActionTick.IsRunning())
        {
            spawnEnemyActionTick   = null;
            waveDurationActionTick = null;
            waveActionTick         = new ActionTick(WaveTick, false);
        }

        //Displaying wave status
        if (waveActionTick != null && waveActionTick.TimeToNextTick < 30000 &&
            waveActionTick.TimeToNextTick > 27000 && !WaveDisplay.gameObject.activeInHierarchy)
        {
            WaveDisplay.Find("Text").GetComponent <Text>().text = "Next Wave in 30 seconds";
            WaveDisplay.gameObject.SetActive(true);
        }
        else if (waveActionTick != null && waveActionTick.TimeToNextTick < 27000)
        {
            WaveDisplay.gameObject.SetActive(false);
        }
    }