Last active
November 23, 2019 20:19
-
-
Save SiarheiPilat/4b6acc0fd771c8960d2fde337ee428a9 to your computer and use it in GitHub Desktop.
This file contains 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; | |
/// <summary> | |
/// The following script converts camera viewport corners' coordinates from viewport to world space. | |
/// </summary> | |
public class ScreenCornersToWorld : MonoBehaviour | |
{ | |
public Camera Camera; | |
public Vector3 BottomLeftCorner, TopLeftCorner, TopRightCorner, BottomRightCorner; | |
void Start() | |
{ | |
if (!Camera) Camera = Camera.main; | |
BottomLeftCorner = Camera.ViewportToWorldPoint(new Vector3(0, 0, Camera.nearClipPlane)); | |
TopLeftCorner = Camera.ViewportToWorldPoint(new Vector3(0, 1, Camera.nearClipPlane)); | |
TopRightCorner = Camera.ViewportToWorldPoint(new Vector3(1, 1, Camera.nearClipPlane)); | |
BottomRightCorner = Camera.ViewportToWorldPoint(new Vector3(1, 0, Camera.nearClipPlane)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment