2025-08-15 17:16:06 +05:00
|
|
|
|
// MeleeEnemy.cs
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class MeleeEnemy : EnemyBase
|
|
|
|
|
{
|
|
|
|
|
protected override void TryAttack()
|
|
|
|
|
{
|
|
|
|
|
if (Time.time - lastAttackTime < config.attackCooldown) return;
|
|
|
|
|
|
|
|
|
|
// still in range?
|
|
|
|
|
if (Vector3.Distance(transform.position, target.position) > config.attackRange) return;
|
|
|
|
|
|
|
|
|
|
// perform attack
|
|
|
|
|
lastAttackTime = Time.time;
|
|
|
|
|
|
|
|
|
|
// Damage the target if it’s damageable
|
|
|
|
|
if (target.TryGetComponent<IDamageable>(out var dmg))
|
|
|
|
|
{
|
|
|
|
|
dmg.ApplyDamage(config.attackDamage);
|
2025-09-02 20:39:37 +04:00
|
|
|
|
GetComponentInChildren<EnemyAnimationController>()?.PlayAttack();
|
|
|
|
|
|
2025-08-15 17:16:06 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: play swing anim / SFX here
|
|
|
|
|
// e.g., GetComponent<Animator>()?.SetTrigger("attack");
|
|
|
|
|
}
|
|
|
|
|
}
|