Skip to content

Instantly share code, notes, and snippets.

@nbrew
Created August 28, 2014 20:30
Show Gist options
  • Save nbrew/27825b801b4919463f2c to your computer and use it in GitHub Desktop.
Save nbrew/27825b801b4919463f2c to your computer and use it in GitHub Desktop.
Unity 3D Make an object full the screen.
using UnityEngine;
public class FillScreen:MonoBehaviour
{
void Update() {
Camera cam = Camera.main;
float pos = (cam.nearClipPlane + 0.01f);
transform.position = cam.transform.position + cam.transform.forward * pos;
transform.LookAt (cam.transform);
// transform.Rotate (90.0f, 0.0f, 0.0f);
float h = (Mathf.Tan(cam.fieldOfView*Mathf.Deg2Rad*0.5f)*pos*2f) /10.0f;
transform.localScale = new Vector3(h*cam.aspect,1.0f, h);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment