Пример #1
0
    // spawn an enemy after X timing period  until units that spawned are equal to the max units this spawner can spawn. Then it destroys itself
    private void StartSpawning()
    {
        if (indexOfSpawnpoints >= spawnPoints.Count)
        {
            indexOfSpawnpoints = 0;
        }
        if (timerForSpawning.GetTime() >= timeForSpawn && unitsCounter <= unitsToSpawn)
        {
            // add this enemy as alive to EnemyManager's list: aliveEnemies
            EnemyManager.GetInstance().AddToList(Instantiate(whatToSpawn, spawnPoints[indexOfSpawnpoints].transform.position, whatToSpawn.transform.rotation).gameObject);
            timerForSpawning.StopAndReset();
            timerForSpawning.StartTimer();
            //Debug.Log("Spawned unit " + unitsCounter + " from position with index " + indexOfSpawnpoints);
            unitsCounter++;
            indexOfSpawnpoints++;
            //MessageDispatch.GetInstance().SendAudioMessageForDispatch("EnemySpawned", this.gameObject.GetComponent<AudioSource>());
            //Debug.Log("unitsCounter " + unitsCounter + " and unitsToSpawn" + unitsToSpawn);
        }
        else if (unitsCounter > unitsToSpawn)
        {
            // remove this spawner from SpawnersManager list: activeSpawners
            SpawnersManager.GetInstance().RemoveFromList(this.gameObject);
            //Debug.Log("spawner removed from list: " + this.gameObject.name);

            Destroy(this.gameObject, 5f);
        }
    }
Пример #2
0
 // if collider triggered start spawning
 private void OnTriggerEnter(Collider collider)
 {
     if (collider.gameObject.tag == "Player" && startSpawing == false)
     {
         Debug.Log(gameObject.name + " triggered");
         SpawnSoundTimer.StartTimer();
         timerForSpawning.StartTimer();
         startSpawing = true;
         // add this spawner to SpawnersManager's list: activeSpawners
         SpawnersManager.GetInstance().AddToList(this.gameObject);
         //MessageDispatch.GetInstance().SendAudioMessageForDispatch("SpawnerTriggered", this.gameObject.GetComponent<AudioSource>());
         //Debug.Log("spawner triggered");
     }
 }
Пример #3
0
 void Awake()
 {
     instance = this;
 }