[Unity3D]正交相機視野範圍OutLine小工具

某些時候,需要根據相機位置,調整遊戲物體的位置。但是不選中相機,就看不到相機的視野範圍,因此,添加此小工具。
直接上代碼:

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));
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章