某些時候,需要根據相機位置,調整遊戲物體的位置。但是不選中相機,就看不到相機的視野範圍,因此,添加此小工具。
直接上代碼:
using UnityEngine;
using System.Collections;
public class CamOutLine : MonoBehaviour
{
public void Start()
{
}
public void OnDrawGizmos()
{
Camera cam = this.GetComponent<Camera>();
Gizmos.DrawWireCube(transform.position+transform.forward*(cam.nearClipPlane+cam.farClipPlane)*0.5f, new Vector3(cam.orthographicSize * 2*cam.aspect, cam.orthographicSize * 2, cam.farClipPlane - cam.nearClipPlane));
}
}