반응형
- 코드 작성
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);
}
}
}
}
}
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 출석체크 7일 간단 구현 Unity Attendance (0) | 2023.10.16 |
---|---|
유니티 C# UI 이미지 FillAmount 서서히 감소시키기 간단 구현 (0) | 2023.09.14 |
유니티 C# Byte[] To String PlayerPrefs 저장 불러오기 간단 구현 (0) | 2023.08.30 |
유니티 C# 슬롯머신 간단 구현 Unity Slot machine (0) | 2023.08.17 |
유니티 C# 맵 상에 직선 궤적 그리기 간단 구현 Line Renderer (0) | 2023.08.13 |
유니티 C# 배경 자동으로 움직이기 Background Scrolling (0) | 2023.08.13 |
유니티 C# 2D 파쿠르 시스템 간단 구현 Parkour (0) | 2023.08.13 |
유니티 C# 회원가입 간단 구현 PlayerPrefs 활용 (0) | 2023.08.13 |
댓글