Created
August 28, 2014 20:30
-
-
Save nbrew/27825b801b4919463f2c to your computer and use it in GitHub Desktop.
Unity 3D Make an object full the screen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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