I would love to know how to keep spawning enemies because when i shoot them they don't spawn. The cause is that the prefab is missing as it says heres my code

var zombiePrefab : GameObject;
var zombiesSpawned : int;
var player : GameObject;
var spawn : boolean;
var minWait : int;
var maxWait : int;
var waitTime : int;

function Start()
{
minWait = 1;
maxWait = 1;
waitTime = Random.Range(minWait, maxWait);;
spawn = true;
}


function Update()
{
if(spawn)
{

Spawn();

}

}


function Spawn()
{

//spawn
Instantiate(zombiePrefab, transform.position, transform.rotation);//spawn at spawner location
zombiesSpawned += 1;
NewWaitTime();
spawn = false;

SetSpawn();
}

function SetSpawn()
{
	yield WaitForSeconds(waitTime);
	spawn = true;
}


function NewWaitTime()
{
waitTime = Random.Range(minWait, maxWait);
}

1 Answer

1

Typically this happens if a person doesn’t use a real prefab. Instead the person uses a game object from the scene and in game play it is killed. One fix is to use a real prefab.

In the Project Pane, right mouse click and select Create/Prefab. Drag the object you want to be a prefab on top of the gray prefab icon. Then drag this prefab on top of zombiePrefab variable.

At this point you can delete the original object (or not).

silly mistake of mine Thank You!;D