반응형
- 코드 작성
using UnityEngine;
public class RotatingDamageObject : MonoBehaviour
{
public float rotationSpeed = 10f;
public float damageAmount = 10f;
public float detectionRadius = 2f;
private void Update()
{
transform.RotateAround(Vector3.zero, Vector3.up, rotationSpeed * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Enemy"))
{
float distance = Vector3.Distance(transform.position, other.transform.position);
if (distance <= detectionRadius)
{
EnemyHealth enemyHealth = other.GetComponent<EnemyHealth>();
if (enemyHealth != null)
{
enemyHealth.TakeDamage(damageAmount);
}
}
}
}
}
반응형