I have this script attached to the player object, and I have another object to send a raycast to call the function “ApplyDamage”.
If i press “g” the level resets perfectly… But if i loose all my hitpoints my computer crashes and comes up with the unity bug reporter message…
var hitPoints : int=100;
var bloodTexture75 : Texture2D;
var bloodTexture50 : Texture2D;
var bloodTexture25 : Texture2D;
var bloodTexture10 : Texture2D;
function Update (){
if(hitPoints <= 0){
Application.LoadLevel(Application.loadedLevel);
}
if(Input.GetKeyDown("g")){
Application.LoadLevel(Application.loadedLevel);
}
}
function ApplyDamage (damage : int){
hitPoints -= damage;
}
function OnGUI (){
if (hitPoints <= 75){
GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), bloodTexture75, ScaleMode.StretchToFill);
}
if (hitPoints <= 50){
GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), bloodTexture50, ScaleMode.StretchToFill);
}
if (hitPoints <= 25){
GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), bloodTexture25, ScaleMode.StretchToFill);
}
if (hitPoints <= 10){
GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height), bloodTexture10, ScaleMode.StretchToFill);
}
}