- Home /
Question by
siddharth3322 · Apr 07, 2014 at 04:57 PM ·
orientationunity4.3landscapeportrait
Shake Device on Orientation Change
I am developing 2d game with landscape and portrait orientation support. I write following code for this purpose.
public class DeviceOrientationController : MonoBehaviour
{
private bool isLandscape;
public GameObject cameraLandscape, cameraPortrait;
public GameObject landscapeView, portraitView;
void Awake ()
{
if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft || Input.deviceOrientation == DeviceOrientation.LandscapeRight && isLandscape)
isLandscape = true;
else
isLandscape = false;
SetOrientaiton ();
}
void Update ()
{
SetOrientaiton ();
}
private void SetOrientaiton ()
{
if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft || Input.deviceOrientation == DeviceOrientation.LandscapeRight && isLandscape) {
ActiveLandscapeView (true);
ActivePortraitView (false);
GameManager.Instance.IsActiveLandscape = true;
isLandscape = false;
} else if (Input.deviceOrientation == DeviceOrientation.Portrait || Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown && !isLandscape) {
ActivePortraitView (true);
ActiveLandscapeView (false);
GameManager.Instance.IsActiveLandscape = false;
isLandscape = true;
}
}
private void ActivePortraitView (bool value)
{
cameraPortrait.SetActive (value);
portraitView.SetActive (value);
}
private void ActiveLandscapeView (bool value)
{
cameraLandscape.SetActive (value);
landscapeView.SetActive (value);
}
}
On device orientation change, I active/de active respective camera. But each time I have to shake my device to view actual layout.
How to come out from this? If you want any more detail then I am ready to provide any time.
Comment
Your answer
Follow this Question
Related Questions
Game support for landscape and portrait 0 Answers
Why do I get lower framerate in Portrait than I do in Landscape? Can I fix this? 1 Answer
IOS orientation loss on scene change 2 Answers
Is is possible for Unity 3D smartphone app to support multiple orientations 1 Answer
Screen orientation change in scenes (unwanted effect) 1 Answer