27 lines
761 B
C#
27 lines
761 B
C#
// 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);
|
||
GetComponentInChildren<EnemyAnimationController>()?.PlayAttack();
|
||
|
||
}
|
||
|
||
// TODO: play swing anim / SFX here
|
||
// e.g., GetComponent<Animator>()?.SetTrigger("attack");
|
||
}
|
||
} |