iLMS知識社群歷程檔Login
Position: 黃國哲 > Unity
1091129 使畫面配合不同的螢幕改變比例
by 黃國哲 2020-11-29 16:17:42, Reply(0), Views(940)





1.選擇Canvas

2.更改UI Scale Mode 成「Scale With Screen Size」

3.將Cavas的Reference Resolution 設定成螢幕的大小

4.將Match 設定成以「高Height」為標準

1為高
0為寬


5.掛上Script腳本

void Awake(){

    CanvasScaler canvasScaler = GetComponent<CanvasScaler>();

    float screenWidthScale = Screen.width / canvasScaler.referenceResolution.x;
    float screenHeightScale = Screen.height / canvasScaler.referenceResolution.y;
  
    canvasScaler.matchWidthOrHeight = screenWidthScale > screenHeightScale ? 1 : 0;
}

Reply