GuidesAPI Reference
Log In

Change Screen Orientation at runtime

Starting with World 1.14.0, you can change the orientation of each screen at runtime.

Please set the Screen Orientation to be displayed by default in World Settings.

  • Orientation : Choose the orientation of the screen.
    • Vertical
    • Horizontal

The following is an example code to change the orientation of the screen at runtime.

Only two screen orientations are supported: Portrait and Landscape.

import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { Button } from 'UnityEngine.UI';
import { Screen, ScreenOrientation } from "UnityEngine"
  
  
export default class ChangeOrientation extends ZepetoScriptBehaviour {
  
    public orientationBtn: Button;
      
  
    Start() {
  
        // When Button click
        this.orientationBtn.onClick.AddListener(() => {
             
            if(Screen.orientation == ScreenOrientation.Landscape)
            {
                // Set Screen Orientation Portrait
                Screen.orientation = ScreenOrientation.Portrait;
            }
            else
            {
                // Set Screen Orientation Landscape
                Screen.orientation = ScreenOrientation.Landscape;
            } 
        });
  
    }
}

πŸ‘

Tip

  • Default UI (Home button, Chat button) and V-pad automatically support landscape-portrait switching when changing Screen Orientation.
  • If you provide other custom UI in your content, you need to respond to the orientation.