Zombie Spawner Not Spawn Zombies

Hello Im making a zombie game, and im trying to make a zombie spawner but the zombies wont spawn please help. Heres My Code:

using UnityEngine;
using System.Collections;

public class ZombieSpawner : MonoBehaviour {

public Transform _Zombie;

public bool HasZombieSpawned = false;

public float SpawnTimer = 0;

public GameObject ZombiePrefab;

public void Update(){
	
	if(HasZombieSpawned == false){
	
	SpawnTimer += Time.deltaTime;
		
	if(SpawnTimer == 10){
	HasZombieSpawned = true;
	GameObject SpawnedZombie = Instantiate(ZombiePrefab, Vector3.zero, Quaternion.identity) as GameObject;
	SpawnedZombie.transform.parent = gameObject.transform;
	SpawnedZombie.transform.localPosition = Vector3.zero;
	SpawnTimer = 0;
	_Zombie = SpawnedZombie.transform;
		
	}
	
	}
	
	if(_Zombie == null){
		HasZombieSpawned = false;
	}
	
}

}

1 Answer

1

The chance that SpawnTimer with exactly be equal to 10 is very small. Change the line 15 to read:

if(SpawnTimer >= 10.0f){