1

Есть два Canvas с разными видами расширениями кнопок "Portrait" и "Landscape" нужно определить в какой ориентации девайс и включить соответствующее меню

My Code (не работает)

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

public class DeviceOrientation : MonoBehaviour {

public GameObject Portrait_Menu;
public GameObject LandscapeLeft_Menu;

// Use this for initialization
void Start () {
    Portrait_Menu.SetActive(false);
    LandscapeLeft_Menu.SetActive(false);
}

// Update is called once per frame
void Update () {

    if (Input.deviceOrientation == DeviceOrientation.Portrait) {
        Portrait_Menu.SetActive(true);
        LandscapeLeft_Menu.SetActive(false);
    }
    else if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft)    {
        Portrait_Menu.SetActive(false);
        LandscapeLeft_Menu.SetActive(true);
    }
}

}

1 ответ 1

1

Используя API. Рассмотрите вариант контроля ориентации или стандартизации, это сэкономит время на поддержку вариантов меню.

if (Input.deviceOrientation == DeviceOrientation.Portrait) {
    // портретная ориентация
}

репо: приложение с примером https://github.com/Tokatak/Test-MobileOrientation

15

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.