I have a menu scene that remains in landscape and another scene accessed from the menu scene using application.loadlevel() which can be all orientations.
I have attached the script below to a game object in both scenes with the flag set for landscape only for the menu and not set for the other scene and this works great on app start.
However if when in the second scene I am in portrait and return to the menu scene it displays the menu incorrectly as it remains in portrait rather than on menu load resetting to landscape only.
Am I doing this the wrong way?
Thanks
public class DeviceOrientation : MonoBehaviour {
public bool landscapeOnly;
void Awake () {
if (landscapeOnly) {
// scene remains in landscape only
Screen.orientation = ScreenOrientation.AutoRotation;
Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;
}
else {
// scene allows auto rotation in all directions
Screen.orientation = ScreenOrientation.AutoRotation;
Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
Screen.autorotateToPortrait = true;
Screen.autorotateToPortraitUpsideDown = true;
}
}
}