- Home /
Resizing orthographic camera to fit 2d sprite on screen
Hi, the following code works for the width:
Camera.main.orthograpthicSize = widthToBeSeen * Screen.height / Screen.width * 0.5;
How to fit the 2d sprite on screen for the width and height.
How do you mean first width then height? How does the order matter? Do you want to actually change your aspect ration to stretch the sprite exactly onto the screen, or do you want the smallest orthographic size so the sprite is still on screen without stretching the aspect ratio.
Answer by UnityCoach · Nov 07, 2018 at 09:56 AM
The size is half the view area height. So this should work :
Camera.main.orthograpthicSize = heightToBeSeen * 0.5f;
That said, I would recommend having a look at Cinemachine.
Your answer
Follow this Question
Related Questions
Changing Ortho Cam Size according to resolution 4 Answers
How can I find out a ViewportToWorldPoint position with a different orthographic size? 1 Answer
Keeping two objects in frame 1 Answer
Set Orthographic Camera To Always Have Y Coordinate Start At Set Position 0 Answers
[2D] Camera movement causes flickering/jittering sprites 2 Answers