Basically I have a scrip to spawn zombies. I would like them to spawn in waves, but that is another story. My issue lies with the main zombie prfab. Whenever I run the game and I kill that first zombie. It no longer will make zombies. How do I fix it?
#pragma strict
------variables start--------
var zombie : Transform;
var clone : Transform;
var zombiesSpawned : int;
var zombies = 11;
var player : GameObject;
var spawn : boolean;
var min : int;
var max : int;
var wait : int;
var spawnPoints : Transform;
var positions : Transform;
------variables end --------
// on start I set min and max, set spawn to true, and set a random number value
function Start ()
{
min = 1;
max = 10;
spawn = true;
wait = Random.Range(min, max);
}
// Update I have an if statement that calls the function Spawn
function Update ()
{
if(spawn)
{
Spawn();
}
}
// The function Spawn is where I believe my issue lies.
//This is where I make more zombies.
function Spawn()
{
if(zombie)
{
Instantiate(zombie, transform.position, transform.rotation);
zombies++;
NewWaitTime();
spawn = false;
SetSpawn();
}
else
{
Instantiate(zombie, transform.position, transform.rotation);
zombies++;
NewWaitTime();
spawn = false;
SetSpawn();
}
}
// a little extra if you can help why isn’t it spawning more than one zombie?
function SetSpawn()
{
if(zombiesSpawned == 0)
{
zombiesSpawned = (zombies + 12);
}
yield WaitForSeconds(wait);
spawn = true;
}
function NewWaitTime()
{
wait = Random.Range(min, max);
}
You should use the code thingy. I don't know what to call it. Just click the button that says "101010", and paste your code into that. Don't paste it straight into the text box, because that's ugly. Here's an example: Without code formatting: function Update() { //Hi, exampleness. if(true) } //Do a thing } } With code formatting: function Update() { //Hi, exampleness. if(true) { //Do a thing } }
– Teledoor24I honestly didn't know how to do that. SO I tried to make it as neat as I could.
– sparky14