Hi all,
I have a game object that is supposed to instantiate other game objects, depending on when they die. Problem is, the code doesn’t seem to work. It creates one enemy, and after it is destroyed (taken care of in another script), it does not enter the EnemyManager() loop again.
Mind taking a looking and seeing what’s wrong with my logic? Thanks!
var tiki : Transform;
var round = 1;
function Awake () {
EnemyManager();
}
function Update () {
var enemyArray = GameObject.FindGameObjectsWithTag("Enemy");
if (!enemyArray)
EnemyManager();
}
function EnemyManager () {
for(i = 0; i < round; i++) {
Instantiate(tiki);
}
round++;
}
Thanks!
I wonder if arrays return booleans too
Try if (enemyArray != null) and see if it works…
from the documentation.
I’m not 100% sure of normal arrays can return null – it would probably depend on the language.
Unfortunately, I tried your suggestion and it did not work. I’ll fiddle around with it some more. If you have any more ideas, feel free to post 'em!
Thanks
Fixed it. Apparently you cannot compare null to an empty array, after it has been initialized with something. I’m assuming there is some garbage in the array.
Browsed through some of my old computer science homework,
if (enemyArray.length < 1)
Is the proper way to check if an array is empty!
Silly me.
Thanks for the help, though!