Physics.CheckBox(transform.position, new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, LayerMask.GetMask("Monster"));
上方代码 以位置transform.position为原点,创建了长宽高为1的立方体,检测Layer为Monster的物体。
此方法只返回是否有符合条件的物体进入,有则返回true;不会有其他信息。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoxCastNonAlloc : MonoBehaviour
{
void Update()
{
bool flage = Physics.CheckBox(transform.position, new Vector3(0.5f, 0.5f, 0.5f), Quaternion.identity, LayerMask.GetMask("Monster"));
if (flage)
{
transform.GetComponent<MeshRenderer>().material.color = Color.green;
}
else
{
transform.GetComponent<MeshRenderer>().material.color = Color.white;
}
}
}