CREATE YOUR WORLD
User Interface
Changing Screen Orientation at runtime
2min
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.
ChangeOrientation
1import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
2import { Button } from 'UnityEngine.UI';
3import { Screen, ScreenOrientation } from "UnityEngine";
4
5
6export default class ChangeOrientation extends ZepetoScriptBehaviour {
7
8 public orientationBtn: Button;
9
10
11 Start() {
12
13 // When Button click
14 this.orientationBtn.onClick.AddListener(() => {
15
16 if(Screen.orientation == ScreenOrientation.Landscape)
17 {
18 // Set Screen Orientation Portrait
19 Screen.orientation = ScreenOrientation.Portrait;
20 }
21 else
22 {
23 // Set Screen Orientation Landscape
24 Screen.orientation = ScreenOrientation.Landscape;
25 }
26 });
27
28 }
29}
👍 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.
Updated 10 Oct 2024

Did this page help you?