using UnityEngine; public class Example : MonoBehaviour { void OnDrawGizmosSelected() { //摄像机近裁剪面距离 float nearClipPlane = Camera.main.nearClipPlane; //定义视口 Rect viewport = new Rect(0, 0, 1, 1); //存放计算结果 Vector3[] outCorners = new Vector3[4]; //计算摄像机近裁剪面四个角的坐标 Camera.main.CalculateFrustumCorners(viewport, nearClipPlane, Camera.MonoOrStereoscopicEye.Mono, outCorners); for (int i = 0; i < outCorners.Length; i++) { //将坐标从摄像机空间转到世界空间 var worldSpacePos = Camera.main.transform.TransformPoint(outCorners[i]); //在Scene场景中绘制小球 Gizmos.color = Color.red; Gizmos.DrawSphere(worldSpacePos, 0.02F); } } }