유니티 박스캐스트
2023. 3. 1. 14:28ㆍ카테고리 없음
using UnityEngine;
public class boxcast : MonoBehaviour
{
public LayerMask collisionMask;
public float boxSize = 0.5f;
public float distance = 0.5f;
void OnDrawGizmos()
{
Vector3 origin = transform.position; // BoxCast 시작 위치
Vector3 direction = transform.forward; // BoxCast 방향
float distance = this.distance; // BoxCast 최대 거리
Vector3 size = Vector3.one * this.boxSize; // BoxCast 크기
Color color = Color.red; // BoxCast 색상
bool hit = Physics.BoxCast(origin, size/2, direction, out RaycastHit hitInfo, transform.rotation, distance);
if (hit)
{
Gizmos.color = Color.green;
//Gizmo.DrawRay(origin, direction * hitInfo.distance, color)
Gizmos.DrawWireCube(origin + direction * hitInfo.distance, size);
}
else
{
Gizmos.color = Color.red;
Gizmos.DrawWireCube(origin + direction * distance, size);
}
}