Skip to content

Instantly share code, notes, and snippets.

@poga
Created September 24, 2013 10:28
Show Gist options
  • Save poga/6682939 to your computer and use it in GitHub Desktop.
Save poga/6682939 to your computer and use it in GitHub Desktop.
while (!targetUnit.IsDead()) {
actor.animation.Play("run");
while (Vector3.Distance(actor.transform.position, target.transform.position) > actorUnit.attackRange) {
actorUnit.MoveTo(target.transform.position);
yield return null;
}
while (Vector3.Angle(actor.transform.forward, target.transform.position - actor.transform.position) > 10) {
actorUnit.RotateToward(target.transform.position);
yield return null;
}
actor.animation.Play("attack");
yield return new WaitForSeconds(actorUnit.attackStartDelay * playbackRate);
// Attack actually happen
actorUnit.Attack(target);
// Wait the rest of animation complete
yield return new WaitForSeconds(attackAnim.length * playbackRate - actorUnit.attackStartDelay * playbackRate);
actor.animation.Play("idle");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment