x


Spawn Script Issue

I have made a spawn script and it has a few issues... Could someone please help me? The Problem is that it uses 'ActiveRecursively' because for my attack script I make it when an enemy has zero health it is not active. But when It starts more than 1 enemy starts and once they die and the next wave come they glitch out a bit when there health is zero.

Here is the Code:

var enemy : GameObject;
var enemy2 : GameObject;
var enemy3 : GameObject;
var enemy4 : GameObject;
var enemy5 : GameObject;
var enemy6 : GameObject;
var enemy7 : GameObject;
var enemy8 : GameObject;
var enemy9 : GameObject;
var enemy10 : GameObject;
var enemy11 : GameObject;
var enemy12 : GameObject;
var enemy13 : GameObject;
var enemy14 : GameObject;
var enemy15 : GameObject;
function Update(){
if (enemy.active == false){
Spawn();
}	
if (enemy2.active == false){
Spawn();
}	
if (enemy3.active == false){
Spawn();
}	
if (enemy4.active == false){
Spawn();
}	
if (enemy5.active == false){
Spawn();
}	
if (enemy.active == false){
Spawn();
}	
if (enemy.active == false){
Spawn();
}	
if (enemy6.active == false){
Spawn();
}	
if (enemy7.active == false){
Spawn();
}	
if (enemy8.active == false){
Spawn();
}	
if (enemy9.active == false){
Spawn();
}	
if (enemy10.active == false){
Spawn();
}	
if (enemy11.active == false){
Spawn();
}
if (enemy12.active == false){
Spawn();
}
if (enemy13.active == false){
Spawn();
}
if (enemy14.active == false){
Spawn();
}
if (enemy15.active == false){
Spawn();
}
}
function Spawn (){
if (enemy.active == false){
enemy2.SetActiveRecursively(true);
}	
if  (enemy2.active == false && enemy.active == false){
enemy3.SetActiveRecursively(true);
}	
if (enemy3.active == false && enemy2.active == false){
enemy4.SetActiveRecursively(true);
}
if (enemy4.active == false && enemy3.active == false) {
enemy5.SetActiveRecursively(true);
}	
if (enemy5.active == false && enemy4.active == false){
enemy6.SetActiveRecursively(true);
}	
if (enemy6.active == false && enemy5.active == false){
enemy7.SetActiveRecursively(true);
}	
if (enemy7.active == false && enemy6.active == false){
enemy8.SetActiveRecursively(true);
}	
if (enemy8.active == false){
enemy9.SetActiveRecursively(true);
}	
if (enemy9.active == false){
enemy10.SetActiveRecursively(true);
}	
if (enemy10.active == false)
enemy11.SetActiveRecursively(true);	
if (enemy11.active == false){
enemy12.SetActiveRecursively(true);
}	
if (enemy12.active == false){
enemy13.SetActiveRecursively(true);
}	
if (enemy13.active == false){
enemy14.SetActiveRecursively(true);
}	
if (enemy14.active == false){
enemy15.SetActiveRecursively(true);
}
}

more ▼

asked Dec 20, 2011 at 12:42 AM

Dreadt9 gravatar image

Dreadt9
-4 6 4 5

Arrays are your friends. Use them. I have no idea what you tried to do with the Spawn() function but it should look a lot more like this (c#):

public GameObject[] Enemies; 

void Update()
{
    for (var i = 0; i < Enemies.Length; i++)
    {
        if(Enemies[i].active == false) Spawn(i);
    }
}
Dec 20, 2011 at 09:24 PM asafsitner
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4865
x4024
x3552
x775
x237

asked: Dec 20, 2011 at 12:42 AM

Seen: 1229 times

Last Updated: Dec 20, 2011 at 09:24 PM