public void Attack(int damage) { if (!_cooldownTimer.IsDone) { return; } InstantiatedAudioPlayer.PlaySound(GetComponent <AudioClipData>(), transform.position); GetComponent <Animator>().SetTrigger("Attacking"); _cooldownTimer.Reset(); var direction = GetComponent <TopDownController>().Direction; var collisions = Physics2D.OverlapBoxAll( new Vector2(transform.position.x, transform.position.y) + direction * (AttackRange / 2), new Vector2(AttackWidth, AttackRange), Vector2.SignedAngle(Vector2.up, direction), EnemyLayers); foreach (var collision in collisions) { var target = collision.GetComponent <Combateer>(); if (target) { target.TakeDamage(damage); var distance = (target.transform.position - transform.position).normalized * KnockbackDistance; target.TakeKnockback(new Vector2(distance.x, distance.y), KnockbackTime); } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player")) { other.GetComponent <Inventory>().AddResource(Resource); InstantiatedAudioPlayer.PlaySound(GetComponent <AudioClipData>(), transform.position); DestroyObject(gameObject); } }
private void TakeDamage(int damage) { if (Invincible) { return; } InstantiatedAudioPlayer.PlaySound(GetComponents <AudioClipData>()[1], transform.position); Health -= damage; if (Health <= 0) { Kill(); } }
private void UpdateAggro() { var distance = (_player.transform.position - transform.position).magnitude; if (_aggro) { if (distance > DeaggroRange) { _aggro = false; } } else { if (distance < AggroRange) { _aggro = true; InstantiatedAudioPlayer.PlaySound(GetComponents <AudioClipData>()[2], transform.position); } } }