Hi, I am trying to make a game where you can stab a enemy with a knife, the problem is that I don’t know how to check if the enemy collides with the player while a attack boolean is set to true, then it will set the health of the enemy to -= 5 every time. Does anyone know how to do this?
Here’s the player srcipt:
static var IsAttacking = false;
var TimeD : float = 1;
function Update () {
IsAttacking = true;
yield WaitForSeconds(TimeD);
IsAttacking = false;
}
Here’s the enemy script:
var Health : float = 100;
var Self : GameObject;
function OnTriggerEnter () {
if(PlayerScript.IsAttacking == true){
Health -=5;
if(Health == 0){
Destroy (Self);
}
}
//Nothing
}