Spawn a variety of enemies

Heya,

I’m working on a sort of zombie survival game, like nazi zombies kind of.

Everything is pretty much done, and now I want to start adding some more variation.

I have 3 types of enemies. I have the normal one, I have the one that explodes when it gets close to you, and I have one that splits into many smaller enemies when you shoot it.

What I need to do is make them spawn randomly from my spawner.
Here is my spawner script:

var Enemy : Transform;
var SpawnController : Transform;
var minWait : int = 1;
var maxWait : int = 10;
var Round : int;
var EnemiesSpawned : int;
function Start()
{	
	Spawn();	
}

function Spawn()
{   
	Instantiate(Enemy, transform.position, transform.rotation);
	SpawnController.SendMessage("AddToSpawn", 1);
	EnemiesSpawned ++; 
	Invoke("Spawn", Random.Range(minWait, maxWait));
}

Basically I want it to have a certain % chance to spawn either one of those enemies instead of a normal enemy.

How would I go about this?

Theres several options available to you
a simple one would be
Rvalue = random.value
if Rvalue < someValue spawn A
if someValue < Rvalue < someOtherValue spawn B
if Rvalue > someOtherValue spawn C

ie get a random value and check where it is in a range 0-0.2, 0.2-0.4, 0.4-1 etc

I’m not sure I follow.

If I generate a random number between 1 and 0, wouldnt the ranges be too small to get any kind of random spawn?

I’m slightly confused.

EDIT:

I got it working. Thanks.

Here is the script for anyone looking to do something similar:

var Enemy : Transform;
var SpawnController : Transform;
var minWait : int = 1;
var maxWait : int = 10;
var Round : int;
var EnemiesSpawned : int;
var spawnChance : float;
var mineEnemy : GameObject;
var splitEnemy : GameObject;
function Start()
{	
	Spawn();
	spawnChance = Random.value;
}

function Spawn()
{	
	spawnChance = Random.value; 
	if(spawnChance <= 0.3)
	{
		Instantiate(Enemy, transform.position, transform.rotation);
	}
	
	if(spawnChance <= 0.6)
	{	
		if(spawnChance > 0.3)
		{
			Instantiate(mineEnemy, transform.position, transform.rotation);
		}
	}
	
	if( spawnChance <= 1)
	{
		if(spawnChance > 0.6)
		{
		Instantiate(splitEnemy, transform.position, transform.rotation);
		}
	}
	SpawnController.SendMessage("AddToSpawn", 1);
	EnemiesSpawned ++; 
	Invoke("Spawn", Random.Range(minWait, maxWait));
}

ya thats pretty much exactly what i was getting at
FYI you can combine your ifs into one line thusly:
if(spawnChance <= 0.6 spawnChance > 0.3) {

You can also use a double-pipeline as an “OR” statement.
i.e.
if(spawnChance < 0.1 || spawnchance > 0.9)
and ^as an “Exclusive-or (XOR)” switch. (only returns true when not both values are equal)