public void OnEscape() { AudioManager.Stop("Slashy_detect"); this.state = SlashyStates.Idle; this.Animator.SetBool("walking", false); this.target = null; }
public IEnumerator Slash() { AudioManager.Play("Slashy_hit"); this.state = SlashyStates.Hit; this.Animator.SetTrigger("attack"); yield return(new WaitForSeconds(0.5f)); Vector2 center = this.Transform.position; var offset = new Vector2(this.SlashHitBoxOffset.x * this.CharacterController.Direction, this.SlashHitBoxOffset.y); center += offset; Collider2D[] collided = Physics2D.OverlapAreaAll(center - this.SlashHitboxSize / 2, center + this.SlashHitboxSize / 2); Debug.DrawLine(center - this.SlashHitboxSize / 2, center + this.SlashHitboxSize / 2, Color.green); foreach (Collider2D collider in collided) { IHitable target = collider.gameObject.GetComponent <IHitable>(); if (collider.gameObject != this.gameObject && target != null) { target.TakeDamages(this.SlashDamages, this.Transform.position); } } yield return(new WaitForSeconds(0.5f)); this.state = SlashyStates.Follow; }
// use incoming events to change state and hadle atacks public void OnDetected(GameObject target) { if (this.state == SlashyStates.Hit) { return; } AudioManager.Play("Slashy_detect"); this.state = SlashyStates.Follow; this.Animator.SetBool("walking", true); this.target = target.GetComponent <Transform>(); }