Script is crashing unity...

The following script causes unity to crash every time I click the play button to leave game mode…

static var health = 100.0;
var maxHealth = 100;
var dieDuration = 3;

//Take damage, die if under 1 hp, update guitext
function ApplyDamage( amount : float ) {

    health -= amount;
    HealthManager.hitPoints = FPSPlayer.health;

    if (health < 1) {
        Die(); 
    } 
}
//tell die to destroy you after set duration
function Die() {

    yield WaitForSeconds( dieDuration );

    Destroy(gameObject);
}
//when you are destroyed reset the level
function OnDestroy()
{
  Application.LoadLevel(0);
}

Any idea why it is causing unity to crash?

Just to verify for the trolls… I know it is this script cause I have tested extensively (including starting a new project) any time this script is in my project the game crashes when leaving game mode, any time I delete it out of the project the problem goes away.

NOTE : I am not getting any error messages in unity saying anything is wrong with this script at all.

Thanks in advance.

1 Answer

1

Try renaming Die to something else. Maybe it’s an undocumented function, similar to PHP’s die function.

I have been using Die in a number of scripts with no problem so I don't think that is the issue. I accidentally deleted my original script and attempted to rewrite it (which is the above script). I know it it at least 95% identical to my last script and my previous script called the Die function (as do all of my enemy damage receiver scripts) because my spawn controller tracks kills using the Die function.