can you correct the “static function OnEnemyDeath()” paragraph so every time an enemy dies it reduces 1 from the total and then when there is no enemies left i want to load a new level (ie. level 2, level 3 and so on). my “var enemy = 5” is the variable that is part of the “static function OnEnemyDeath()”.
public var explosionPrefab : Transform;
var beep : AudioClip;
var enemy = 5;
function OnCollisionEnter(col: Collision){
if (col.gameObject.tag == “Player”){
Destroy(col.gameObject);
audio.PlayOneShot(beep);
}
}
static function OnEnemyDeath()
{
if(col.gameObject.tag == “Player”) enemies-= 1) Application.LoadLevel(“level 2”);
}
public var explosionPrefab : Transform;
var beep : AudioClip;
var enemy = 5;
function OnCollisionEnter(col: Collision){
if (col.gameObject.tag == "Player"){
Destroy(col.gameObject);
audio.PlayOneShot(beep);
}
}
static function OnEnemyDeath()
{
if(col.gameObject.tag == "Player"){
Score -= 1; //this variable hasn't been declared.
enemy -= 1;
}
if (enemy <=0)
//you'll have to keep track of the current level somewhere and stick it in here
Application.LoadLevel("level " + (currentLevel + 1));
}
I think that should work (may require a little tweaking - like declaring your level, etc) but that’s the gist of it.
you need to change to:
static var enemy = 5;
and then you can access it from any enemy.
and just add in the OnEnemyDeath()
enemy--;
if(enemy==0) Application.LoadLevel("level 2");