- Home /
Know when screen orientation has changed on mobile? better to keep one orientation?
How can I know when a user has changed the screen orientation in a game? and is it better to lock it to one orientation anyway?
Answer by fafase · Aug 23, 2015 at 04:08 PM
Based on your game, you may want to lock it. Some games allows to rotate, then the UI needs to be done so that it does not go weird.
Simple way to check for rotation:
public class OrientationSystem:MonoBehaviour{
public Action<DeviceOrientation> OnOrientationChange = ()=>{};
private DeviceOrientation previous = DeviceOrientation.Unknown;
private void Start(){
previous = Input.deviceOrientation;
}
private void Update(){
if(previous != Input.deviceOrientation){
previous = Input.deviceOrientation;
OnOrientationChange( Input.deviceOrientation);
}
}
private void OnDestroy(){ OnOrientationChange = null; }
}
Other way is to create a bridge between the native side and Unity.
I'm in 2 $$anonymous$$ds whether to lock it, I like the freedom of giving people the option to hold the device how want, but it might be a lot less work just locking it to one.
Answer by Wolfshadow · Aug 23, 2015 at 01:27 PM
My guess is you are having the mobile trouble where proportions change with the auto rotate. I just went to the build menu, player settings, and selected on rotation view. I think this is what you want to do, but, if not, I might be able to get back to you. Bye!
Your answer
![](https://koobas.hobune.stream/wayback/20220612000955im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mobile Orientation / input.acceleration problems 0 Answers
Splash screen orientation - iOS 2 Answers
Calibrating Accelerometer Values 1 Answer
point the north 1 Answer