Showing camera view frustrum in Scene view

We’ve been working on a 2D game in Unity3D and I’d written this a while back to show the view frustrum of the camera in the scene view and had been meaning to post it:

Yellow wireframe outlines view frustrum. Top is scene view, bottom is game view

Create a new c# script in Unity and call it “DrawCameraViewFrustrum.cs”.  Copy/paste the code below and attach it to your camera object in your scene.

using UnityEngine;
using System.Collections;

public class DrawCameraViewFrustrum : MonoBehaviour
{	
	public Color clr = new Color(0.1f, 0.14f, 0.8f, 0.5f);
	public void OnDrawGizmos()
    {	
		Gizmos.color = clr;
		Gizmos.DrawWireCube(transform.position, new Vector3((camera.orthographicSize*camera.aspect)*2, camera.orthographicSize*2, 10));
	}
}


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s