using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraAdaptation : MonoBehaviour {
public float initSize;//初始摄像机size
public float initWith;//初始分辨率的宽
public float initHeight;//初始分辨率的高
float factWidth;//设备屏幕实际宽
float factHeight;//设备屏幕实际高
void Start() {
//获取设备屏幕实际宽
factWidth = Screen.width;
//获取设备屏幕实际高
factHeight = Screen.height;
//摄像机适配后的size
GetComponent<Camera>().orthographicSize = initSize * ((initWith/initHeight)/(factWidth/factHeight));
//全屏显示
Screen.fullScreen = true;
}
void Update() {
if (Input.GetKey(KeyCode.Space)) {//按下空格,退出全屏
Screen.fullScreen = false;
Debug.Log("退出全屏");
}
}
}