Archive for the ‘ 2D ’ Category

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