게임개발/게임플랫폼 응용 프로그래밍
OverlapSphere
pudding81
2024. 3. 8. 12:16
Physics.OverlapSphere 메서드는 특정 범위 내에 있는 충돌체들을 감지하는 데 사용됩니다.
이 메서드는 3D 프로젝트와 2D 프로젝트 모두에서 지원되며, 다양한 모양의 충돌체를 처리할 수 있습니다
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SphereVisualizer : MonoBehaviour
{
public Color color;
public Woman woman;
private void OnDrawGizmos()
{
Gizmos.color = color; // 알파 확인
Gizmos.DrawWireSphere(woman.center.transform.position, woman.radius);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Woman : MonoBehaviour
{
public Transform center;
public float radius;
private void Start()
{
Collider[] colliders= Physics.OverlapSphere(center.transform.position,this.radius);
Debug.LogFormat("콜라이더 수{0}",colliders.Length);
}
}