有时候我们做固定平面的3D游戏的时候,有3D镜头适配的需求,最近正好遇到了,临时编了一个,拿出来和大家一起分享:
using UnityEngine; using System.Collections; public class ScreenUnit : MonoBehaviour { private float height = 480; private float width = 854; private float rate1 = 480 / 854.0f; private float rate2; // Use this for initialization void Start () { rate2 = Screen.height / (float)Screen.width; gameObject.GetComponent<Camera>().fieldOfView *= 1 + (rate2 - rate1); } }
将脚本托给相机,就可以实现简单的多机型3D视觉适配
时间: 2024-10-24 00:50:32