using UnityEngine; public class Example : MonoBehaviour { public float distance = -1.0F; void OnDrawGizmosSelected() { //获取摄像机空间转世界空间的转换矩阵 Matrix4x4 m = Camera.main.cameraToWorldMatrix; //摄像机前面distance位置 Vector3 cameraSpacePos = new Vector3(0, 0, distance); //摄像机空间转世界空间 Vector3 worldSpacePos = m.MultiplyPoint(cameraSpacePos); //在worldSpacePos位置绘制一个黄色球(仅Scene窗口中可见) Gizmos.color = Color.yellow; Gizmos.DrawSphere(worldSpacePos, 0.2F); } }