Unity之2D游戲界面相機(jī)適配
來源:程序員人生 發(fā)布時(shí)間:2015-05-11 09:10:31 閱讀次數(shù):5792次
之前寫的關(guān)于2D游戲界面相機(jī)的水平、豎直、以人為中心3種模式的相機(jī)控制,我寫著寫著,總感覺相機(jī)適配有點(diǎn)繁瑣,而且適配得不怎樣好,多平臺的時(shí)候由于資源有限我也不知道有無完全適配,今天給大家分享1下我今天寫的1個(gè)2D游戲場景相機(jī)適配,感覺挺好的,有需要的可以用著試試看,接下來我貼上代碼:
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;
}
}
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)