Unity c# determines whether the object is within the camera's perspective

Vector3 pos = Camera.main.WorldToScreenPoint(transform.position); //Get the position of the current UI on the screen

  //Judge the relationship between the current position and screen coordinates

if ((pos.z <0) || (pos.x <0) || (pos.x > Screen.width) || (pos.y <0) || (pos.y > Screen.height))
  Debug.Log("Disappeared in the screen");
else
  Debug.Log("Displayed in the screen");

Guess you like

Origin blog.csdn.net/qq_21743659/article/details/133748052