When I run the project from within Unity, the player’s movement is clipped in the x direction to the camera as expected. All is great. But, if I do a build for Windows, for example, the player can move all the way to the edges of the physical screen. It does stop at the screen boundaries, so it’s like my camera is now the full physical display size.
Okay. I got it working, but I sort of feel that I still must have missed something unless the code in the course isn’t really correct for a build. What I did is below.
private void SetUpMoveBoundaries() {
var canvas = FindObjectOfType<Canvas>();
var canvasScaler = canvas.GetComponent<CanvasScaler>();
var resolution = canvasScaler.referenceResolution;
float aspectRatio = resolution.x / resolution.y;
xPadding = GetComponent<SpriteRenderer>().sprite.bounds.extents.x;
xMax = aspectRatio * Camera.main.orthographicSize - xPadding;
xMin = -xMax;
}
Hi SteveBee,
Good job on fixing the issue yourself. Our game was created for an aspect ratio of 9:16. In the Build Settings > Player Settings, you would have to set a resolution with that aspect ratio. If that didn’t work, you would have to delete the Player Prefs.
Alternatively, you could calculate the padding like you did.
1 Like
Thanks, Nina.
That all makes sense. I was worried I’d missed something, but it looks like I didn’t.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.