U3D如何判断一个GameObject是否在屏幕内
更新:HHH   时间:2023-1-7


A物体有CameraB渲染,首先将A物体世界坐标转换为屏幕坐标,再由屏幕坐标的x与Screen.width做比较,如果x<Screen.width则在屏幕内,否则在屏幕外。

Vector3 screen3dPos = CameraB.WorldToScreenPoint(enemy.transform.position);

if (screen3dPos.x > Screen.width)

{

    Debug.Log("out of screen");

}else{

    Debug.Log("in screen");

}


返回开发技术教程...