Create number of enemies when one is deid

Hello everyone…

Her is the thing. Im doing a game for fun…
so far i manged to do the Terrain, FPS Controller, Now im in the enemy
part of the game…

So far i managed to make the character animate when its dead and it follows the user.

Now the question i have …

How i can make the script creates a random enemies when all of them die…???

Any recommended improvements???
Thanks…

Enemy Script/…

    var Player : Transform;
    var MoveSpeed = 4;
    var MaxDist = 10;
    var MinDist = 5; 
    public var Health = 100; 
     
    function Start ()
    {
     
    }
     
    function Update ()
    {
    transform.LookAt(Player);
     
    if(Vector3.Distance(transform.position,Player.position) >= MinDist)
    {
     
    transform.position = transform.position + transform.forward*MoveSpeed*Time.deltaTime;
    
      	if(Health >=1){
	     	animation.Play("walk");
     	}else if (Health <= 0){
	     	animation.CrossFade("die");
	     	Destroy(gameObject, 2);
     	}
     
	    if(Vector3.Distance(transform.position,Player.position) <= MaxDist)
	    {
	        if(Health >=1){
	     		animation.CrossFade("attack");
	     	}else if (Health <= 0){
		     	animation.CrossFade("diehard");
		     	Destroy(gameObject, 2);
	     	}
	    	
	    }
     
    } 
    }

public function applyDamage(health : int){

	Health = Health - health;

}
// When the enemy is hit animat...
// But i can seem to make Yeild To WORK....!!!!!!
function gotHit(){
animation.CrossFade("resist");
yield WaitForSeconds(1);
}

function Test(){
Debug.Log(this.name);
}

Your pointers are appreciated

  1. You don’t need to check the scene for enemies, ever, if your spawner spawns them in the beginning and is then informed by the enemy on their death. If it spawns 10 enemies and all ten let it know that they’re dead then the spawner knows that there are no more enemies in the scene.
  2. You can use a single enemy prefab or, if you have multiple enemy types, several prefabs chosen randomly, weighted by type, or manually designed.
  3. Each GameObject that you instantiate is already unique, so take that as you will.

You haven’t asked about the where of things, and that is actually the hardest part. I would probably have a few spawn markers and then spawn your enemies in a random angle and distance from that center point. I haven’t done that part for you in my example, but it should get you moving in the right direction.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Spawner : MonoBehaviour
{
	public int maxInstances;
	public bool respawnAtZero;
	public GameObject[] prefabs;
	public GameObject[] spawnPoints;
	
	private List<GameObject> activeSpawn;
	
	void Awake()
	{
		activeSpawn = new List<GameObject>(maxInstances);
		Spawn();
	}
	
	void Spawn()
	{
		for (int i = 0; i < maxInstances; i++)
		{
			Transform spawnPoint = spawnPoints[Random.Range(0, spawnPoints.Length)];
			activeSpawn.Insert(i, GameObject.Instantiate(prefabs[Random.Range(0, maxInstances)], spawnPoint.position, spawnPoint.rotation));
			activeSpawn*.SendMessage("NotifyMeOnDeath", this, SendMessageOptions.DontRequireReceiver);*
  •  }*
    
  • }*

  • void HandleOnSpawnDied(GameObject go)*

  • {*

  •  activeSpawn.Remove(go);*
    
  •  if (activeSpawn.Count == 0)*
    
  •  	Spawn();*
    
  • }*
    }

All you have to do to make this work is make a complimentary script to place on your enemies which will listen for the “NotifyMeOnDeath” message and know what to do with it. Namely, it should tell the spawner that it’s dead!