- Home /
Question by
HuskyPanda213 · Mar 28, 2013 at 04:40 AM ·
spawnerzombies
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;
}
}
}
Comment
Answer by robertbu · Mar 28, 2013 at 04:44 AM
The chance that SpawnTimer with exactly be equal to 10 is very small. Change the line 15 to read:
if(SpawnTimer >= 10.0f){
Your answer
![](https://koobas.hobune.stream/wayback/20220613095233im_/https://answers.unity.com/themes/thub/images/avi.jpg)