Hello guys, I’m doing my first Unity game and I want user can play it in portrait and landscape. The game have a UI/canvas area that with a script I turn on or off. It works well. And the game area that It’s 3d graphics. With another script I modify the aspect ratio of the game changing the viewport rect of the camera. Something like this:
…
if (scaleheight < 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight) / 2.0f;
camera.rect = rect;
}
else // add pillarbox
{ … }
This script is called at start to change to the right camera aspect and It’s called too when you change from portrait to landscape or landscape to portrait with the android device.
In Unity editor it works well. I select portrait or landscape and play the game and It works. In my Android device It doen’t work well. Only It works when I rotate the android device and the view changes. But If I have my Android device in my hands in portrait orientation and I play the game, the script has no effect. Any idea?