我有一台正交相机 . 视口rect的值如下...
x = 0 y = 0 W = 1 H = 1
假设我有两个比例尺为1的立方体 . 一个是x = 0,一个是x = 1.现在假设正交相机在x = 0.5(立方体之间的中间),在立方体上方俯视它们,为了让立方体占据整个屏幕宽度,我需要多大的尺寸来制作相机?
您是否有任何特殊原因试图使用视口rect?如果你只是改变相机的正交尺寸 . [1817671]
Link to Unity's API on Camera.orthoGraphic size
如果您正试图将它们精确地装入相机的 width ,那么您必须根据宽高比更改正交尺寸 .如果你试图将它们完全适合 height ,则正交尺寸将为1 .
我希望您可以使用此代码根据不同的屏幕尺寸使相机的正交尺寸不同 .
看看代码块:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraScaler : MonoBehaviour { public float scrnHeight =800f; public float scrnWidth =480f; public float tempRation = 1; public const float fixedValue = 3f ; //public Vector2 nativeRes = new Vector2 (480,800); void Awake() { scrnHeight = Screen.height; scrnWidth = Screen.width; tempRation = scrnWidth / scrnHeight; Debug.Log (Screen.height); Debug.Log (Screen.width); Debug.Log (tempRation); Camera.main.orthographicSize = fixedValue / tempRation; } }
2 回答
您是否有任何特殊原因试图使用视口rect?
如果你只是改变相机的正交尺寸 . [1817671]
Link to Unity's API on Camera.orthoGraphic size
如果您正试图将它们精确地装入相机的 width ,那么您必须根据宽高比更改正交尺寸 .
如果你试图将它们完全适合 height ,则正交尺寸将为1 .
我希望您可以使用此代码根据不同的屏幕尺寸使相机的正交尺寸不同 .
看看代码块: