Hi everyone!
The question is in the title. I am making a 2D arcade game for Android in which the player should be able to choose screen orientation. The problem is that when changing screen orientation of a mobile device, the camera changes zoom. This also occurs with different resolutions. How do I stop this?
It might also be helpful to know that this doesn’t affect GUI and that the camera is orthographic.
Cheers!
If anyone else is wondering this, I found a solution for negating the zoom caused by changing screen orientation but not for changing resolution:
[ExecuteInEditMode]
public class ZoomController : MonoBehaviour
{
public float spriteHeight;
private void OnGUI()
{
Camera.main.orthographicSize = Screen.height / spriteHeight / 2.0f;
}
}
The field spriteHeight is optional, but if set to how many pixels high your sprites are per unit of space, you can get pixel perfect sprite rendering.