Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Getting errors with ScreenOrientation.Portrait

Discussion in 'Scripting' started by JayCally80, Sep 18, 2014.

  1. JayCally80

    JayCally80

    Joined:
    Aug 6, 2014
    Posts:
    38
    I'm trying to set the screen orientation to portrait for my mobile game and am getting the below error.

    error CS0117: `ScreenOrientation' does not contain a definition for `Portrait'

    I'm using
    Code (CSharp):
    1. Screen.orientation = ScreenOrientation.Portrait;
    to set the orientation to portrait but its not working.

    Can anyone tell me what I'm doing wrong? Or how do I prevent the auto-rotation? Its a vertical shooter and I want it to stay in portrait.

    Thanks
     
  2. JayCally80

    JayCally80

    Joined:
    Aug 6, 2014
    Posts:
    38
    Think i figured it out.

    Code (CSharp):
    1. void Awake () {
    2.         Screen.autorotateToPortrait = true;
    3.         Screen.autorotateToPortraitUpsideDown = true;
    4.         Screen.autorotateToLandscapeRight = false;
    5.         Screen.autorotateToLandscapeLeft = false;
    6.     }
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'd guess you named your own class ScreenOrientation and it has no definition for Portrait.

    --Eric
     
  4. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    you can find control for that under build settings without the need for code (fyi)