[Unity3D] how to recognize screen edges and unity3d Recognition
Problems
- The unit of length in Unity3D is meters.
- The unit of Screen information obtained using Screen. resolutions is pixel.
That is to say, even if the screen information and parameters are obtained, the information cannot be converted into information that can be used in the editor. At that time, I wanted to do Protect The Red.
So we started our Google journey.
I flipped through StackExchange and Unity Answers, and finally understood it. The general idea is like this.
Solution
Code Implementation
[HideInInspector]public float leftBorder; [HideInInspector]public float rightBorder; [HideInInspector]public float topBorder; [HideInInspector]public float downBorder;
private float width;
private float height;
void SetBasicValues(){
//the up right corner
Vector3 cornerPos=Camera.main.ViewportToWorldPoint(new Vector3(1f,1f,
Mathf.Abs(-Camera.main.transform.position.z)));
leftBorder=Camera.main.transform.position.x-(cornerPos.x-Camera.main.transform.position.x);
rightBorder=cornerPos.x;
topBorder=cornerPos.y;
downBorder=Camera.main.transform.position.y-(cornerPos.y-Camera.main.transform.position.y);
width=rightBorder-leftBorder;
height=topBorder-downBorder;
}
Achievements-keep red
The final result is that the wall game remains on the four sides of the screen after running. Control the ball in the screen.
APK Download
Google Play