- Home /
Hurting enemy when attacking status is equal to true and player is colliding with enemy object.
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
}
Answer by sammo · May 10, 2013 at 12:09 PM
You can't use a yield coroutine within function update()
I recommend moving
IsAttacking = true;
yield WaitForSeconds(TimeD);
IsAttacking = false;
into a new function and calling that when the player attacks.
Your answer
Follow this Question
Related Questions
Enemy following Player on uneven surface 1 Answer
FPS , not attackking if the player behind ? 0 Answers
AI controller script, Enemy movement issues 0 Answers
Ai Alien Zombies get stuck on trees? 0 Answers