Currently i have an animation which attacks the player within so many units in its range, only issue is that i have tried to use yield new return WaitForSeconds method. That didn't work out at all.
if (direction.magnitude > 1) {
this.transform.Translate (0, 0, 0.05f);
anim.SetBool ("IsWalking", true);
anim.SetBool ("IsAttacking", false);
} else {
anim.SetBool ("IsAttacking", true);
print ("Attacking");
Vector3 fwd = transform.TransformDirection (Vector3.forward);
print ("Attacking");
waiting();// HERE IS WHERE IT DOESNT WORK
/*RaycastHit hitInfo;
if (Physics.Raycast (transform.position,fwd, out hitInfo, 1)) {
if (hitInfo.collider.tag == "Player") {
objectHealth = hitInfo.collider.GetComponent<Health> ();
objectHealth.TakeDamage(0.05f);
}
}*/
anim.SetBool ("IsWalking", false);
}
Here is the waiting function:
IEnumerator waiting(){
yield return new WaitForSeconds(8);
Vector3 fwd = transform.TransformDirection (Vector3.forward);
print ("Attacking");
// waiting(){
RaycastHit hitInfo;
if (Physics.Raycast (transform.position,fwd, out hitInfo, 1)) {
if (hitInfo.collider.tag == "Player") {
objectHealth = hitInfo.collider.GetComponent<Health> ();
objectHealth.TakeDamage(0.05f);
}
}
}
What does work is that commented part. if i comment out the waiting, and uncomment that comment block with the raycast hit stuff, works beautifully, but the health is going down continuously, not periodically. Any help would be appreciated.
Follow @SLO_MMORPG