need help with damage

Hello i am learning to use javascript and i am currently making a health script but am struggling with making some kind of damage and death system where when my health reaches 0 my body is replaced with a ragdoll here is my script i am in the process of making:

@script ExecuteInEditMode()
var healthTexture : Texture2D;
var healthBorder : Texture2D;
var healthBack : Texture2D;
var deathScreen : Texture2D;
var maxhealth : int = 100;
var curhealth : int = 100;

function OnGUI () {

GUI.DrawTexture(Rect(43,Screen.height - 65,314,36), healthBorder);
GUI.DrawTexture(Rect(43,Screen.height - 65,314,36), healthBack);

var adjust : int = curhealth * 3;
GUI.BeginGroup(Rect(55,Screen.height - 55,adjust,15));
GUI.DrawTexture(Rect(0,0,290,15), healthTexture);
GUI.EndGroup();
}

function Update () {

if (curhealth < 0)
curhealth = 0;

if (curhealth > maxhealth)
curhealth = maxhealth;

}

so i have a GUI and i have a way to keep my player from having negative health or more than the maxhealth. If you could help me make a damage and death function or even show me in the right direction via tutorial (which would probably be best so i can learn)
-Thanks :slight_smile:
Jester0813

I’d suggest heading over to the Teaching Forum to read and follow all the tutorials you can. Lots of good help over there.

Good Luck

-Christopher

I would do something like this, im no pro though.

its a concept i would use.

var ragdoll = GameObject;
var health : int = 100;

function Update ()
{
if (health <= 0)
   {
   // maybe destroy this game object 
   // instantiate gameobject ragdoll
   }
}