Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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

Switch to Tall & Wide game view in editor 0 Answers

Mobile Landscape Orientation switching width with height? 0 Answers

How can I make only one scene landspace? other ones are portrait 0 Answers

GameObjects in same size for any orientation 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges