iLMS知識社群歷程檔登入
位置: 黃國哲 > Unity
1090407 更改畫面Camera的大小
by 黃國哲 2020-04-07 20:21:56, 回應(0), 人氣(1107)




有三種模式的畫面調整:

1.使用預設值,也就是螢幕比例改變時畫面不會更動,
   而是直接把多餘的部分截掉不顯示。





2.透過程式Code調整畫面大小,參考BLOG

//定義遊戲開發時所使用的基礎解析度寬高
public float baseWidth = 1024;
public float baseHeight = 768;

void Awake(){
    camera.aspect = this.baseWidth / this.baseHeight;
}

使用這個做法,當畫面大小改變,會使得畫面被拉長或是壓縮。


3.當畫面比例改變時,透過等比例的縮放去調整。

public float baseWidth = 1024;
public float baseHeight = 768;
public float baseOrthographicSize = 5;

void Awake(){

    float newOrthographicSize = (float)Screen.height / (float)Screen.width * this.baseWidth / this.baseHeight * this.baseOrthographicSize;
    camera.orthographicSize = Mathf.Max(newOrthographicSize , this.baseOrthographicSize);
}















回應