Unity c# 判断物体是否在摄像机视角内

Vector3 pos = Camera.main.WorldToScreenPoint(transform.position); //取得当前UI在屏幕当中的位置

  //判断当前的位置 与屏幕坐标的关系

if ((pos.z <0) || (pos.x <0) || (pos.x > Screen.width) || (pos.y <0) || (pos.y > Screen.height))
  Debug.Log("消失在屏幕中");
else
  Debug.Log("显示在屏幕中");

猜你喜欢

转载自blog.csdn.net/qq_21743659/article/details/133748052