Unity之2D游戲界面相機適配
來源:程序員人生 發布時間:2015-05-11 09:10:31 閱讀次數:5796次
之前寫的關于2D游戲界面相機的水平、豎直、以人為中心3種模式的相機控制,我寫著寫著,總感覺相機適配有點繁瑣,而且適配得不怎樣好,多平臺的時候由于資源有限我也不知道有無完全適配,今天給大家分享1下我今天寫的1個2D游戲場景相機適配,感覺挺好的,有需要的可以用著試試看,接下來我貼上代碼:
using UnityEngine;
using System.Collections;
public class CameraControl_2D : MonoBehaviour {
// 默許屏幕大小
float width = 854.0f;
float height = 480.0f;
// Use this for initialization
void Awake()
{
// 屏幕適配
float orthographicSize = this.GetComponent<Camera>().orthographicSize;
print("aa:" + orthographicSize);
orthographicSize *= (Screen.height / (float)Screen.width) / (height / width);
print("bb:" + orthographicSize);
this.GetComponent<Camera>().orthographicSize = orthographicSize;
}
}
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈