I have a spawn script and i want waves to start ONLY if there are no other enemies present in the scene, but i can’t find a way to check if an enemy is instantiated. Here is my script:
using UnityEngine;
using System.Collections;
public class CrappyEnemySpawner : MonoBehaviour {
public GameObject Enemy;
public bool Enabled;
public GameObject SpawnPoof;
public float SpawnChanceIsOneIn;
public float CurrentWave;
public float EnemiesPerRound;
public float WaveStartDelay;
public float WaveDelay;
public bool Wave;
public GameObject SpawnedEnemy;
// Use this for initialization
void Start () {
SpawnedEnemy = GameObject.FindGameObjectWithTag("Enemy");
CurrentWave = 1;
Wave = true;
}
// Update is called once per frame
void Update () {
if (SpawnedEnemy.activeInHierarchy){
Debug.Log ("No Enemies");
}
if (Wave == false){
WaveStartDelay += 1 ;
}
if (WaveStartDelay > WaveDelay){
Wave = true;
}
if (SpawnChanceIsOneIn<50 && Wave == true){
SpawnChanceIsOneIn -= 3f;
} else {
SpawnChanceIsOneIn -= 0.1f;
}
if(Random.Range(1,100)>SpawnChanceIsOneIn && Enabled==true && Wave == true){
Instantiate(Enemy, transform.position, transform.rotation);
}
if(SpawnChanceIsOneIn<EnemiesPerRound && Wave == true){
Debug.Log ("Congrats! You've made it to wave" + CurrentWave);
CurrentWave += 1f;
WaveDelay *= 1f;
Wave = false;
EnemiesPerRound -= 1.5f;
SpawnChanceIsOneIn=100;
}
}
}
Thanks in advance!