- Home /
Question by
TyrionR · May 05, 2015 at 01:47 PM ·
camerascreentoworldpointboundaryviewporttoworldpoint
Screen Boundary Solutions
Hello,
I found two piece of code in unity answers to set the screen boundaries. I want to know if there is any advantage using one over than the other.
maxlimit = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width,Screen.height,0f));
minlimit = Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0f));
Second one:
float camDistance = Vector3.Distance(transform.position, Camera.main.transform.position);
Vector2 bottomCorner = Camera.main.ViewportToWorldPoint(new Vector3(0,0, camDistance));
Vector2 topCorner = Camera.main.ViewportToWorldPoint(new Vector3(1,1, camDistance));
minX = bottomCorner.x;
maxX = topCorner.x;
maxY = topCorner.y;
minY = bottomCorner.y;
Comment
Your answer
Follow this Question
Related Questions
Viewport to World Coordinates 2 Answers
What makes Camera.ScreenToWorldPoint return different results with same input? 0 Answers
How to find world coordinates of screen corners with a camera angle 2 Answers
Constraining a perspective camera in World Y? 0 Answers
Camera.main.ScreenToWorldPoint return camera position 2 Answers