• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by siddharth3322 · Apr 15, 2016 at 11:35 AM · androidscreenorientationlandscapeportrait

ScreenOrientation.PortraitUpsideDown not working

I want to set orientation of device to PortraitUpsideDown. For this purpose, I have written some test code. Here it is :

 void Update ()
     {
         if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft && Screen.orientation != ScreenOrientation.LandscapeLeft) {
             Debug.Log ("landscape left");
             Screen.orientation = ScreenOrientation.LandscapeLeft;
         } else if (Input.deviceOrientation == DeviceOrientation.LandscapeRight && Screen.orientation != ScreenOrientation.LandscapeRight) {
             Debug.Log ("landscape right");
             Screen.orientation = ScreenOrientation.LandscapeRight;
         } else if (Input.deviceOrientation == DeviceOrientation.Portrait && Screen.orientation != ScreenOrientation.Portrait) {
             Debug.Log ("portrait");
             Screen.orientation = ScreenOrientation.Portrait;
         } else if (Input.deviceOrientation == DeviceOrientation.PortraitUpsideDown && Screen.orientation != ScreenOrientation.PortraitUpsideDown) {
             Debug.Log ("portrait upside down");
             Screen.orientation = ScreenOrientation.PortraitUpsideDown;
         }
     }

Here in this all orientations condition become true only for 2 times. While PortraitUpsideDown become keep on running when I set my device to that orientation.

Why it is not running as like other orientations code?? Please give me your suggestion for this. Is it possible android device not contains that orientation?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aditya · Apr 15, 2016 at 11:56 AM 0
Share

you wrote 16 lines of code to perform a task that could be done by just setting Player settings >> Default Orientation to Auto Rotation ... WHY ?

avatar image antx · Apr 15, 2016 at 11:58 AM 0
Share

Just to make sure: did you enable all the wanted screen orientations in the player settings? Otherwise the app will be build without the ability to use them.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by aditya · Apr 15, 2016 at 11:59 AM

remove else if and use only if or even better use switch and even best just set Player Settings >> Resolutions and Presentation >> Default Orientation to Auto Rotation

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image siddharth3322 · Apr 15, 2016 at 12:45 PM 0
Share

Basically I want to detect orientation change in my game. Because for landscape and portrait, I have different game play views. Something similar to Candy Crush. Now give me suggestion for above.

avatar image aditya siddharth3322 · Apr 15, 2016 at 01:41 PM 0
Share

then simply set the Default screen orientation in Player settings to Auto Rotation and through script just check what is the current orientation using Screen.Orientation, coz of this Unity will handle your Orientations and you just had to make two variables one for current orientation and other for previous orientation ... if this helps please accept the ANSWER

avatar image siddharth3322 aditya · Apr 15, 2016 at 01:50 PM 0
Share

I am already going to up vote this answer because of time as well proper reply. I am implementing same so get back to you.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

61 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

screen auto rotation forth and back 1 Answer

GameObjects in same size for any orientation 0 Answers

Switch to Tall & Wide game view in editor 0 Answers

Mobile Landscape Orientation switching width with height? 0 Answers

Bugged android screen 7 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges