- Home /
hit delay does not kick in
well I have a enemy following my Player till the enemy gets close enougn. then it does a attack animation and after that my player should take 1 hit and then after the animation played again 1 hit again till the players hits it can take variable hits 0 and then it should debug PLayer Died! the log
but what happens is that when the enemy gets close enough the hits he takes start going up like crazy and then after that the log starts spamming the player died like 300 times and even when I'm not in the attackrange anymore he just keeps building up does anyone have a goos solution for this?
first script var Target : Transform; var Speed : float; var Hit = 1; var HitDelay : float = 1;
function Update () {
Target = GameObject.FindWithTag("Player").transform;
var distance = Vector3.Distance(gameObject.transform.position, Target.transform.position);
if(distance > 2) {
GetComponent.<Animation>().Play("walk");
var Step = Speed * Time.deltaTime;
var lookPos = Target.position - transform.position;
lookPos.y = 0;
var Rotation = Quaternion.LookRotation(lookPos);
transform.rotation = Quaternion.Slerp(transform.rotation, Rotation, 1);
transform.position = Vector3.MoveTowards(transform.position, Target.position, Step);
}
else if(distance < 2) {
Attack();
}
}
function Attack() {
GetComponent.<Animation>().Play("attack");
yield WaitForSeconds(HitDelay);
Target.transform.SendMessage("PlayerHitted", Hit, SendMessageOptions.DontRequireReceiver);
}
and the script that reacts to it
var PlayerCanTake = 5;
function Update () {
if(PlayerCanTake <= 0){
Debug.Log("Player died!");
//Application.LoadLevel(Application.LoadedLevel);
}
}
function PlayerHitted(Hit : int) {
Debug.Log("took hit");
yield WaitForSeconds(1);
PlayerCanTake -= Hit;
}
Your answer
Follow this Question
Related Questions
how to make an AI damage a third person controller ? 1 Answer
How do I get my enemy to attack? 0 Answers
Can anyone help with me with my attack script and enemy script? 1 Answer
Why does this extremely simple script return an error? 1 Answer
First script plays animation but second script stops if from playing said animation 1 Answer