示例#1
0
    IEnumerator DelayedSpawn(SpawnCore.EnemyType enemyType)
    {
        // Don't let spawning back to back continuously
        spawnCoolDown = true;

        // Spawn the enemy according to the wishes from above
        if (enemyType == SpawnCore.EnemyType.Enemy0)
        {
            SpawnEnemy0(spawnPool0.GetSpawn());
        }
        else
        {
            Debug.LogError("<Spawner> Stupid idiot, that enemy type don't exist");
        }

        // Increment stats
        SpawnCore.IncreaseSpawnTotals();

        // Wait until allowing to spawn again
        yield return(new WaitForSeconds(SpawnCore.spawnDelay));

        // THEN allow spawning again
        spawnCoolDown = false;
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
                #if UNITY_EDITOR
        // Spawn an enemey if e key is pressed
        if (Input.GetKeyDown("e"))
        {
            // If not active, don't continue
            if (!active)
            {
                print("<Spawner> Spawner inactive");
                return;
            }

            // FOR GETTING TIMING BETWEEN SPAWNING ENEMIES
            if (lastSpawnTime == 0f)
            {
                print("Setting first spawn time");

                // Set initial lastSpawnTime
                lastSpawnTime = Time.time;
            }
            else
            {
                print("Time Between Spawns: " + (Time.time - lastSpawnTime));

                // Reassign lastSpawnTime
                lastSpawnTime = Time.time;
            }

            // Increase the amount spawned
            SpawnCore.IncreaseSpawnTotals();

            // Actually spawn the enemy
            SpawnEnemy0(spawnPool0.GetSpawn());
        }

        // Print spawn statistics
        if (Input.GetKeyDown("s"))
        {
            print("<---- Printing Spawn Statistics ---->");

            print("Total Spawned: " + SpawnCore.totalSpawned);
            print("Current Wave: " + SpawnCore.currentWave);
            print("This Wave's Goal: " + SpawnCore.thisWave_goal);
            print("This Wave's Spawned: " + SpawnCore.thisWave_spawned);
            print("This Wave's Destroyed: " + SpawnCore.thisWave_defeated);

            print("<-- End Spawn Statistics -->");
        }
                #endif

        // If the Spawner is active...
        if (active)
        {
            // If not enough spawns have been made to reach this spawn's goals
            if (SpawnCore.thisWave_defeated < SpawnCore.thisWave_goal)
            {
                // If spawn is NOT on cool down, then continue spawning
                if (!spawnCoolDown)
                {
                    // Spawn an enemy
                    StartCoroutine(DelayedSpawn(SpawnCore.EnemyType.Enemy0));
                }
            }             // end thisWaveGoal != thisWaveSpawn

            // Else check that the number destroyed == thisWaveGoal
            else if (SpawnCore.thisWave_goal <= SpawnCore.thisWave_defeated)
            {
                // Activate the next wave
                SpawnCore.NextWave();

                print("Current Wave: " + SpawnCore.currentWave);
            }
        }
    }