我在地板上画了一个圆圈。所有通过那个圆圈的东西都应该被发现。以下代码正在工作:
void Update () {
RaycastHit hit;
Ray landingRay = new Ray (transform.position, Vector3.up);
// This debug does not seem to work:
Debug.DrawRay (transform.position, Vector3.up * 50);
if( Physics.Raycast(landingRay, out hit) ){
Debug.Log("raycast is working!");
}
}
但是,我认为RayCast只是我画的雪碧(1)的中心,所以它不包括整个圆圈(2):
是否有一种最佳的方法来执行此操作?还是应该在同一个脚本中编写几个RayCast呢?
发布于 2015-08-12 17:52:49
你想要做的是一个SphereCast
RaycastHit hit;
float radius = 5f;
float distance = 50f;
Ray landingRay = new Ray (transform.position, Vector3.up);
if (Physics.SphereCast(landingRay, radius, out hit, distance)
{
// Do something
}
https://stackoverflow.com/questions/31971652
复制相似问题