25 lines
680 B
C#
Raw Normal View History

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 its damageable
if (target.TryGetComponent<IDamageable>(out var dmg))
{
dmg.ApplyDamage(config.attackDamage);
}
// TODO: play swing anim / SFX here
// e.g., GetComponent<Animator>()?.SetTrigger("attack");
}
}