Help with zombies Spawning

hey i am making a zombie game and i have to make them spawn i have a script but when the zombies spawn they dont kill me i need help here is the script:

var zombiePrefab : GameObject;

InvokeRepeating(“SpawnZombie”, 4, 4);

function SpawnZombie() {

Instantiate(zombiePrefab, transform.position, transform.rotation);

}

You probably have some logic that’s not recognizing the new zombies. If you’re looking for them by name, an instance usually adds “(Clone)” to the end of the prefab’s name. Could be that.

here is a much better spawning script that i personaly made :slight_smile:

var AISpawn : Transform[];
var allEnemies : GameObject[];
static var currentEnemies : int = 0;
var maxEnemies : int = 1;
var minEnemies : int = 0;
var spawn = false;  
var spawnTime : float;    
static var enemiesDead : int;   
var enemies : int;   
var round : int = 0;   
var roundText : GUIText;   

function Start()
    {
        while (true)
        {
           if(currentEnemies <= 1)
          {
              currentEnemies = 0;
              spawnTime -= 0.1f;
              ZombieAI2.speed += 0.3;
              round += 1;
              maxEnemies += 2;
          }
            if (currentEnemies <= minEnemies) 
                spawn = true; // if minEnemies reached start spawning
            if (currentEnemies >= maxEnemies) 
                spawn = false; // if maxEnemies reached stop spawning
            if (spawn){ // if spawning enabled create new enemy
                // Randomize the different enemies to instantiate.
                var obj : GameObject = allEnemies[Random.Range(0, allEnemies.length)];
                // Randomize the spawnPoints to instantiate enemy at next. 
                var pos: Transform = AISpawn[Random.Range(0, AISpawn.length)];  
                Instantiate(obj, pos.position, pos.rotation); 
                currentEnemies +=1;
            }
            yield WaitForSeconds(spawnTime); // free Unity for 2 seconds each loop anyway
        }
    }
function Update()
{
    roundText.text = round + "";
    enemies  =  currentEnemies;
    if(spawnTime <= 0.9)
       {
         spawnTime = 0.9;
       }
    if(maxEnemies >= 50)
       {
         maxEnemies = 50;
       }
	if(round == 50)
		{
			GO_PlayerDamageReciever.hitPoints = 100;
		}
}

It is not to do with your enemy spawner. It has something to do with the prefab that you are instantiating. Look down the prefab in the inspector and see if the prefab has gaps such as None(GameObject) or it is missing scripts on the prefab. That was the case when I had a similar situation.

Hey!

Here a video tutorial that I found : Enemy Spawner. It work really well I tested it out.

Hope I’ll help you,
Nbo

Add this script to your enemy

var enemyHealth : float = 10;
var RecieveDamage : boolean;
var DestroyAfterTime : float = 30;
var DestroyAfterTimeRandomization : float = 0;
@HideInInspector
var countToDie : float;
var playerDist : int;
var playerCapsule : GameObject;
var Attacking : boolean;





function Start()
{
	playerCapsule = GameObject.FindGameObjectWithTag("Player");
	Attacking = false; 
	
}

function Awake()
{
	DestroyAfterTime += Random.value * DestroyAfterTimeRandomization;
}

function Update()
{
	playerDist = Vector3.Distance(playerCapsule.transform.position, transform.position);
	
	if(playerDist <= 2)
	{
		if(!Attacking)
		{
			Invoke("ApplyDamage", 1);
		}	
	}
}

	
function ApplyDamage()
{
	playerCapsule.SendMessage("minusHealth");
	Attacking = false;
}

/////////////////////////////and this one to your player and they will kill you no problem. :) \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

var playerHealth : int;
var playerScript : PlayerMovementScript;
var player : Rigidbody;



function Start () 
{
	playerHealth = 100;
}

function Update () 
{
	if(playerHealth <= 0)
	{
		playerHealth = 0;
		Death();
	}
		 
}

function Death()
{
	print("You Are Dead");
	rigidbody.isKinematic = true;
	rigidbody.freezeRotation = false;
	playerScript.enabled = false;
	
}

function minusHealth()
{
	playerHealth -=1;
}