Armor/defense systeme

Hello !
I try to do a armor/defense systeme.i have life systeme :

#pragma strict
private var life_max : int ;
public var life_current : int ;

function Start (){
life_max = 100 
life_current = 100
}

function Update (){

//simulate damage
if(Input.GetKeyUp("t"))
{
life_current -= 10 ;
}

//hud
function OnGUI(){
GUI.Box(Rect(10,10,200,30), life_current) ;

So actually, if i take damage, my player loose 10 life.
Now i want create an armor system, and if i have 100 armor when i take 10 damage, my armor should loose 10.
and when armor=0 , damage continu on my life.

Any idea ?

First, with unity if your variables are myVariable the editor will show them as “My Variable” in the inspector and it’s easier to read. It’s easier to type (imo) in code as well.

As for your question, add another Armor variable. armor_max, armor_current

if(armor_current > damageTaken)
{
armor_current -= damageTaken;
}
else
{
if(life_current > damageTaken)
{
life_current -= damageTaken;
}
else
{
//player dead
}
}

As a caveat, if you have 3 armor and take 10 damage, it will go straight to health. This was a rather easy question for you to ask since you practically had the code in your script already! You just needed to think about your armor.

Some ideas, yes. Guarantee they will work, not so much, I’m still somewhat of a noob anyway.

First, you need to make sure your script knows you have armor. Then, it needs to see how much armor is left, and once there is no more, take away from life.

And so:
var armor : float;

function Update () {
 if(Input.GetKeyUp("t"))
{
if (armor >=0)
armor -= 1-;
else
life_current -= 10
}
}

That’s all you should need to implement that much, but to make the damage come from an outside source will require more work.