Projext/Assets/5.TestScript/DamageBot.cs

14 lines
437 B
C#
Raw Normal View History

2026-01-29 06:58:38 +00:00
using UnityEngine;
public class DamageBot : MonoBehaviour
{
[SerializeField] private float damageAmount = 10f, damageInterval = 1.0f;
private float timer;
private void OnTriggerStay(Collider other)
{
if (other.TryGetComponent<IDamageable>(out var target))
{
timer += Time.deltaTime;
if (timer >= damageInterval) { target.TakeDamage(damageAmount); timer = 0f; }
}
}
}