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");
}
时间: 2024-10-13 00:02:10