OK I cobled together a simple "Alien Zombie" spawner using an empty game object and attaching a spawn script. I have about 3 of them strategically placed on my game terrain and they spawn every 200 seconds which after a lot of test playing I think is a fairly safe number to allow my players to explore the terrain and figure out where they need to go and what they need to do.
But just in case I'm wondering if there is a way to make this spawn ONLY a certain number of Alien Zombies over a certain time period.
Say something like after a maximum of 200 Zombie Aliens (Number to be tweaked based on ammo caches available on my terrain) STOP spawning them so that if my player runs out of ammo or takes longer to figure out where and what to do that they won't get OVERRUN with Alien Zombies.
I hope this makes sense, if not, let me know and I'll try explaining it in another way ;)
var alienZombiePrefab : GameObject;
InvokeRepeating("SpawnZombie" , 200, 200);
function SpawnZombie () {
Instantiate(alienZombiePrefab, transform.position, transform.rotation);
}
EDIT
Almo this is what's in my Awake function in my AlienZombieAI script from what you have done bellow:
function Awake (){
var tempobj : GameObject = GameObject.FindWithTag("ZombieCounter");
var countScript : ZombieCountScript countScript = tempobj.GetComponent(ZombieCountScript);
countScript.m_numZombies++;
var tempobj : GameObject = GameObject.FindWithTag("ZombieCounter");
var countScript : ZombieCountScript = tempobj.GetComponent(ZombieCountScript);
countScript.m_numZombies--;
}
I get an error for line 17: Assets/WeaponScripts/ZombieAlienAI.js(17,44): UCE0001: ';' expected. Insert a semicolon at the end.
Which is this line:
var countScript : ZombieCountScript countScript = tempobj.GetComponent(ZombieCountScript);
EDIT: *Almo*:
I changed my code to this in my AI script:
function Awake (){
var tempobj : GameObject = GameObject.FindWithTag("ZombieCounter");
var countScript : ZombieCountScript = tempobj.GetComponent(ZombieCountScript);
countScript.m_numZombies++;
}
Now I get the following errors: Error 1: Assets/Misc Scripts/ZombieCountScript.js(6,24): BCE0019: 'm_numZombies' is not a member of 'ZombieCountScript'.
Error 2 Assets/Misc Scripts/ZombieCountScript.js(8,29): BCE0005: Unknown identifier: 'alienZombiePrefab'.
Error 3 Assets/WeaponScripts/ZombieAlienAI.js(18,21): BCE0019: 'm_numZombies' is not a member of 'ZombieCountScript'.
????
My Zombie Counter Script:
function SpawnZombie () {
var tempobj : GameObject = GameObject.FindWithTag("ZombieCounter");
var countScript : ZombieCountScript = tempobj.GetComponent(ZombieCountScript);
if(countScript.m_numZombies < 200)
{
Instantiate(alienZombiePrefab, transform.position, transform.rotation);
}
}
There are some other bits, like initializing the zombiecount variable, but this should get you started.
– almoWould the object tagged "ZombieCounter" be an empty game object that I could just toss in anywhere in my scene? And by Zombie Script do you mean my AI script for my Alien Zombies?
– anon48034950Yup, ZombieCounter is just an empty object to attach the counter script to for access from multiple spawners. Yes, ZombieScript is whatever script you use to run the zombies. If you want to stop spawning entirely once 200 is reached, then just do CancelInvoke calls on the spawners once there are 200. If you want 200 spawned, not 200 in existence, then don't do m_numZombies--.
– almoAwesome almo I'll have to try this out ASAP :D
– anon48034950I followed your instruction and it's giving me a load of errors?
– anon48034950