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");
}