need help with autorotation
Hi All,
I want to restrict the orientation using script. For android tablet or iPad, i want landscape only For android mobile or iPhone, portrait mode only.
I used below code to check iPad or iPhone, and everything works fine
if (SystemInfo.deviceModel.Contains("iPad"))
{
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;
Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
}
else
{
Screen.autorotateToPortrait = true;
Screen.autorotateToPortraitUpsideDown = true;
Screen.autorotateToLandscapeLeft = false;
Screen.autorotateToLandscapeRight = false;
}
Screen.orientation = ScreenOrientation.AutoRotation;
And for Android, i am using:
bool isLandscape = false;
float optionValue = (Screen.width < Screen.height ? Screen.width : Screen.height);
float screenHeightInInch = optionValue / Screen.dpi;
if (screenHeightInInch < 3.1) {
// Phone
isLandscape = false;
} else {
// Tablet
isLandscape = true;
}
if (isLandscape) // Landscape
{
Screen.autorotateToPortrait = false;
Screen.autorotateToPortraitUpsideDown = false;
Screen.autorotateToLandscapeLeft = true;
Screen.autorotateToLandscapeRight = true;
}
else
{
Screen.autorotateToPortrait = true;
Screen.autorotateToPortraitUpsideDown = true;
Screen.autorotateToLandscapeLeft = false;
Screen.autorotateToLandscapeRight = false;
}
Screen.orientation = ScreenOrientation.AutoRotation;
For Android device also everything works fine. But When i hold android mobile in landscape mode, the unity start in landscape mode and build content also shows in landscape mode. if i hold the device in portrait mode, everything is in portrait mode.
I am doing anything wrong?
I have attached demo project, try to load it on android mobile and make sure you hold device in landscape mode. You will see message "I am Android Mobile, so in Portrait mode!", but the device orientation is landscape.
Why not simply set the option in the Build/Player settings?
These parameters are actually placed in the manifest on Android.
cause i want to support both type of devices Tablet and $$anonymous$$obile and i don't want to build two separate builds.
http://answers.unity3d.com/questions/994680/how-to-detect-if-the-device-is-android-mobile-or-t.html
Hopefully if the link still works it contains a method of deter$$anonymous$$ing if its a tablet or phone. Thats step 1 anyway.
You say it works on iOS but not Android. As I stated, device orientation needs to be 'allowed' in the manifest. Check your player settings and your manifest.xml
Thanks meat5000 for your comment Yes for android i need to manage playersetting/manifest, but using script And m not getting how could i do that