Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Android | Change Orientation

Discussion in 'Scripting' started by TechnoObi, Oct 7, 2014.

  1. TechnoObi

    TechnoObi

    Joined:
    Nov 30, 2013
    Posts:
    82
    Is there a way to change the Default Orientation (Android) with a script?
     
  2. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
  3. TechnoObi

    TechnoObi

    Joined:
    Nov 30, 2013
    Posts:
    82
    But I have this:
    Code (csharp):
    1.  
    2. if (Input.GetKeyDown(KeyCode.Space))
    3.             {
    4.                
    5.                 if (camera == 2 && !currentCamera)
    6.                 {
    7.                     Camera3D.enabled = true;
    8.                     Camera2D.enabled = false;
    9.                     Screen.orientation = ScreenOrientation.Portrait;
    10.                     camera++;
    11.                     currentCamera = true;
    12.                     Debug.Log(Screen.orientation);
    13.                 }
    14.  
    15.                 if (camera == 3 && !currentCamera)
    16.                 {
    17.                    
    18.                     Camera2D.enabled = true;
    19.                     Camera3D.enabled = false;
    20.                     Screen.orientation = ScreenOrientation.LandscapeLeft;
    21.                     camera = camera - 1;
    22.                     currentCamera = true;
    23.                     Debug.Log(Screen.orientation);
    24.                 }
    25.             }
    26.  
    But in the Console I always get "Portrait". Is there an error?
     
  4. novashot

    novashot

    Joined:
    Dec 12, 2009
    Posts:
    373
    not sure what your var "currentCamera" is used for but... in both if's you check if it is false. The first time when it is set to portrait that var gets set to true and never gets changed back in the course of what I see here so the second if will never fire since currentCamera = true.
     
  5. TechnoObi

    TechnoObi

    Joined:
    Nov 30, 2013
    Posts:
    82
    I set it here back:
    Code (csharp):
    1.  
    2. void Update () {
    3.         if (!collided.collided)
    4.         {
    5.             ChangeCamera();
    6.         }
    7.        
    8.         currentCamera = false;
    9.     }
    10.  
    11.     void ChangeCamera()
    12.     {
    13.         if (touch)
    14.         {
    15.  
    16.         }
    17.  
    18.         if(!touch)
    19.         {
    20.            
    21.             if (Input.GetKeyDown(KeyCode.Space) || touched.pressedmitte)
    22.             {
    23.                
    24.                 if (camera == 2 && !currentCamera)
    25.                 {
    26.                     Camera3D.enabled = true;
    27.                     Camera2D.enabled = false;
    28.                     Screen.orientation = ScreenOrientation.Portrait;
    29.                     camera++;
    30.                     currentCamera = true;
    31.                     Debug.Log(Screen.orientation);
    32.                 }
    33.  
    34.                 if (camera == 3 && !currentCamera)
    35.                 {
    36.                    
    37.                     Camera2D.enabled = true;
    38.                     Camera3D.enabled = false;
    39.                     Screen.orientation = ScreenOrientation.LandscapeLeft;
    40.                     camera = camera - 1;
    41.                     currentCamera = true;
    42.                     Debug.Log(Screen.orientation);
    43.                 }
    44.             }
    45.         }
    46.  
    47.     }
    48.