코어, 벽, 적의 생성 및 충돌, 데미지 판정
This commit is contained in:
26
Assets/Scripts/Enemy/EnemyAttack.cs
Normal file
26
Assets/Scripts/Enemy/EnemyAttack.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyAttack : MonoBehaviour
|
||||
{
|
||||
[Header("Attack Settings")]
|
||||
[SerializeField] private float damage = 10f;
|
||||
[SerializeField] private float attackCooldown = 1.0f; // 공격 간격 (1초)
|
||||
|
||||
private float _nextAttackTime = 0f;
|
||||
|
||||
// EnemyAttack.cs
|
||||
private void OnCollisionStay(Collision collision)
|
||||
{
|
||||
if (Time.time >= _nextAttackTime)
|
||||
{
|
||||
// 상대방에게서 IDamageable 인터페이스가 있는지 확인
|
||||
IDamageable target = collision.gameObject.GetComponent<IDamageable>();
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
target.TakeDamage(damage);
|
||||
_nextAttackTime = Time.time + attackCooldown;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user