等下會使用到螢幕位置的參數,而這些參數的意思可以參考我上一篇文章:

Unity輸出到手機上的螢幕方向選擇(靜態)

 

在畫面上放一個Cube,這樣在螢幕轉換位置時可以明顯看出來。同時新增一個C# script,命名為test

 

開始撰寫程式碼:

 


using UnityEngine;
using System.Collections;

public class test : MonoBehaviour
{
    void OnGUI()
    {
        if (GUILayout.Button("left"))
            Screen.orientation = ScreenOrientation.LandscapeLeft;
        if (GUILayout.Button("right"))
            Screen.orientation = ScreenOrientation.LandscapeRight;
        if (GUILayout.Button("Upside"))
            Screen.orientation = ScreenOrientation.PortraitUpsideDown;
    }
}


在Player Settings上將 Default Orientation 設定為 Portrait ,這樣的話程式一執行畫面就會保持著直立的狀態,直到我們按下GUI按鈕改變狀態為止。

然後將程式拖到Main Camera上,之後輸出apk到手機上執行即可。

arrow
arrow
    全站熱搜

    Yang 發表在 痞客邦 留言(0) 人氣()