2026-06-11 사운드시스템 (BaseScene참고)
This commit is contained in:
44
Assets/02_Scripts/ZoneTrigger.cs
Normal file
44
Assets/02_Scripts/ZoneTrigger.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
|
||||
//구역마다 트리거 콜라이더를 하나씩 두고 어떤 구역인지 지정해서 사용.
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class ZoneTrigger : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Zone _zone; //이 영역이 나타내는 구역
|
||||
[SerializeField] private string _playerTag = "Player"; //플레이어로 인식할 태그
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
//이 컴포넌트를 붙이면 콜라이더를 자동으로 트리거로 설정
|
||||
GetComponent<Collider>().isTrigger = true;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (!other.CompareTag(_playerTag)) return;
|
||||
if (GameManager.Instance == null) return;
|
||||
|
||||
//구역 상태만 바꾸면, BGM 등은 OnZoneChanged 구독자가 알아서 반응한다
|
||||
GameManager.Instance.SetZone(_zone);
|
||||
}
|
||||
|
||||
//에디터에서 구역 범위를 시각화
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Collider col = GetComponent<Collider>();
|
||||
if (col == null) return;
|
||||
|
||||
Gizmos.color = new Color(0f, 1f, 1f, 0.15f);
|
||||
Gizmos.matrix = transform.localToWorldMatrix;
|
||||
|
||||
//박스/구 콜라이더만 간단히 표시
|
||||
if (col is BoxCollider box)
|
||||
{
|
||||
Gizmos.DrawCube(box.center, box.size);
|
||||
}
|
||||
else if (col is SphereCollider sphere)
|
||||
{
|
||||
Gizmos.DrawSphere(sphere.center, sphere.radius);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user