if(hit.gameObject.tag == "EnemyBullit")
{
PlayerStats.HEALTH -= 20;
}
here is part of my script which ruducts health from my player iif hit by it
however this is very glitch as sometimes the bullit hits me and this does not reduct health is there a better way to go about this.
please help than ;)
i think it would be better if you put something like this on the bullet.
(I,G)
var damage : int = 20;
var playerTag : String;
function OnCollisionEnter (hit : Collision) {
if(hit.gameObject.tag == playerTag){
hit.gameObject.SendMessage("ApplyDamage",damage);
}
}
this code has to be in a script on the bullet.
there are three things that you need to do for this to work
1# you need to give the player a tag and make sure that you type the name of the tag in the
var playerTag.
2# you need to make a function in the player script with the name ApplyDamage.
like this:
function ApplyDamage(damage : int){
HEALTH -= damage;
}
insert this code in a script on the player
hope this helps! :)