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.
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
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)