Studio GuideWorld SDK Guide
Log In
World SDK Guide

Changing Screen Orientation 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.