So basically this script resizes a plane to fit on the whole area that the camera is rendering. I’m using it to play a movie on the back while animating a character.
And the code:
1 2 3 4 5 6 7 8 9 10 11 12 |
void Start () { float distance = Vector3.Distance(Camera.main.transform.position, transform.position); float sizeHeight = Mathf.Tan(Mathf.Deg2Rad * Camera.main.fieldOfView/2) * distance; float radAngle = Camera.main.fieldOfView * Mathf.Deg2Rad; float radHFOV = 2 * Mathf.Atan(Mathf.Tan(radAngle / 2) * Camera.main.aspect); float hFOV = Mathf.Rad2Deg * radHFOV; float sizeWidth = Mathf.Tan(Mathf.Deg2Rad * hFOV/2) * distance; transform.localScale = new Vector3(sizeWidth*2, sizeHeight*2, 10); } |