/// <summary>
/// 从相机发射射线 返回hitPoint 若未射到物体,返回值为相机forward加rayRange的范围点
/// </summary>
/// <param name="rayCamera"> 发射射线的相机</param>
/// <param name="rayRange">未射到物体时,返回的射线可达最大范围值</param>
/// <returns> 确定瞄准点 </returns>
public static Vector3 CameraRayPosition(Camera rayCamera,int rayRange)
{
RaycastHit hit;
Ray ray = new Ray(rayCamera.transform.position, rayCamera.transform.forward);
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
return hit.point;
}
else
{
return rayCamera.transform.position + (rayCamera.transform.forward * rayRange);
}
}
来源:CSDN
作者:ysong0913
链接:https://blog.csdn.net/ysong0913/article/details/103715483