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