- Home /
Bug?... Handling Android phone auto rotation orientation changes
SOLVED by updating to the latest version of Unity (v5.3.1f1).
- Here's a Youtube video
Note: the video shows buggy behavior, but those bugs are eliminated in the latest version of Unity (v5.3.1f1)
I set the Build Settings to have Default Orientation set to Auto Rotation
I initially setup my camera in landscape orientation
- I adjust the Camera orthographicSize when the phone rotates to portrait orientation
If I don't do this then the camera seems too "zoomed in" I have a (black) background image behind a grid of (blue) sprites
Here is my orientation handling code...
using UnityEngine; using System.Collections;
public class myOrientationHandler : MonoBehaviour { float LandscapeSize; bool isPortrait = false;
void Awake () {
LandscapeSize = Camera.main.orthographicSize;
StartCoroutine (myCheckOrientation ());
}
IEnumerator myCheckOrientation(){
yield return new WaitForSeconds(0.5f);
if (!isPortrait && Camera.main.aspect <= 1) {
isPortrait = true;
print ("PORTRAIT MODE !!!");
Camera.main.orthographicSize = LandscapeSize / Camera.main.aspect;
} else if (isPortrait && Camera.main.aspect > 1) {
isPortrait = false;
print ("LANDSCAPE MODE !!!");
Camera.main.orthographicSize = LandscapeSize;
}
StartCoroutine (myCheckOrientation ());
}
}
Answer by Kurius · Jan 20, 2016 at 09:13 PM
SOLVED by updating to the latest version of Unity (v5.3.1f1). Moderators, please remove "Bug?..." from title of this thread. Thank you. Those of you who are interested, the code I posted earlier works perfectly. Just add that script to your camera. Note: the code assumes your camera is initially setup in Landscape mode.