- Home /
How to apply screen wrapping fit for any resolution?
I have a little script for screen-wrapping but it only works for a certain resolution and not in general. //Screen Wrapping done void CheckBounds() { if (this.transform.position.x <= -9.11f) { this.transform.position = new Vector3(9.11f, this.transform.position.y, 0); } if (this.transform.position.x > 9.11f) { this.transform.position = new Vector3(-9.11f, this.transform.position.y, 0); } if (this.transform.position.y <= -5.6f) { this.transform.position = new Vector3(this.transform.position.x, 5.6f, 0); } if (this.transform.position.y > 5.6f) { this.transform.position = new Vector3(this.transform.position.x, -5.6f, 0); } }
UPDATE I managed to do it by applying screen.width and screen.height, but is there a more efficient way?
void CheckBounds()
{
if (this.transform.position.x <= -Screen.width)
{
this.transform.position = new Vector3(Screen.width, this.transform.position.y, 0);
}
if (this.transform.position.x > Screen.width)
{
this.transform.position = new Vector3(-Screen.width, this.transform.position.y, 0);
}
if (this.transform.position.y <= -Screen.height)
{
this.transform.position = new Vector3(this.transform.position.x, Screen.height, 0);
}
if (this.transform.position.y > Screen.height)
{
this.transform.position = new Vector3(this.transform.position.x, -Screen.width, 0);
}
}
Your answer
Follow this Question
Related Questions
Why doesn't my players camera work and why does it spaz out randomly 1 Answer
why my unity games run on android devieces,the screen will be wrong. 0 Answers
Render application at a different resolution than screen 1 Answer
Screen Coordinates of an object's corners 2 Answers
Keeping screen width and scaling screen height for different screen resolutions 2 Answers