Exemplo n.º 1
0
    void Update()
    {
        // if the GO is activated and I can spawn another enemy
        if (activate && enemiesSpawned.Count < maxEnemyToSpawn)
        {
            timer -= Time.deltaTime;

            // and the timer is over
            if (timer <= 0)
            {
                // I spawn an enemy around the spawnpoint
                Vector3 position = AIEnemy.GenerateRandomPosition(spawnPoint.position, 2, NavMesh.AllAreas);

                Instantiate(particleSpawnPrefab, position, Quaternion.identity);
                audioSource.PlayOneShot(spawnClip);

                // A spawned enemy don't have to drop gears
                GameObject e = Instantiate(enemyPrefab, position, Quaternion.identity);
                e.GetComponent <AIEnemy>().canDropItem = false;
                enemiesSpawned.Add(e);

                timer = timeBeforeSpawn;
            }
        }

        if (enemiesSpawned.Count > 0)
        {
            CheckToDestroy();
        }
    }