U
U
UniProger2021-02-11 23:54:33
Android
UniProger, 2021-02-11 23:54:33

How to set horizontal orientation in Unity for Android?

Greetings. I need to make sure that the game on android opens only in landscape orientation. In the documentation, the unit read that the functions that I wrote in Awake are responsible for this business. But when testing the game through UnityRemote, I can easily change the orientation on the phone. In what there can be a problem, prompt.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BackGroundSize : MonoBehaviour
{
    void Awake()
    {
        Screen.autorotateToLandscapeLeft = false;
        Screen.autorotateToLandscapeRight = false;
        Screen.autorotateToPortrait = false;
        Screen.autorotateToPortraitUpsideDown = false;
        Screen.orientation = ScreenOrientation.Portrait;


    }
    void Start()
    {
        var height = Camera.main.orthographicSize * 2f;
        var width = height * Screen.width / Screen.height;
        transform.localScale = new Vector3(width, height, 0);
    }

 
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question