- Home /
help with script load level on 0 enemies
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");
}
Answer by Chris D · Jun 03, 2011 at 07:11 PM
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.
enemy is still not declared as static. i don't think this will work.
totally right, whoops I'll fix that up...or not - website's being weird. In any case, your answer should take care of it :D
Answer by iggy · Jun 03, 2011 at 07:13 PM
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");
static var enemy = 5;
function OnCollisionEnter(col: Collision){
if(col.gameObject.name == "Cube"){
Destroy(col.gameObject);
Application.LoadLevel("level 1");
}
}
static function OnEnemyDeath() { if(col.gameObject.tag == "Player"){ Score -= 1; //this variable hasn't been declared. enemy -= 1; } enemy--; if(enemy==0) Application.LoadLevel("level 2"); } }
(24,1): BCE0044: expecting EOF, found '}'.
I am looking for same script help, could you post what worked for you if you were able to fix?
Thanks!
Your answer
Follow this Question
Related Questions
load level on collision 2 Answers
Load Scene by audio clip 2 Answers
How the scene works 1 Answer
Problem LoadLevel 1 Answer
Multiple Instances of My Current Scene? 0 Answers