Unity正交相机尺寸属性

时间:2015-01-02 10:45:09

标签: unity3d camera orthographic

我有一台正交相机。视口rect的值如下...

x = 0
y = 0
W = 1
H = 1

让我们说我有两个比例尺为1的立方体。一个是x = 0,一个是x = 1.现在让我们说正交相机在x = 0.5(中途)立方体,在立方体上方俯视它们,我需要多大的尺寸来制作相机,以便立方体占据整个屏幕宽度?

2 个答案:

答案 0 :(得分:1)

您是否有任何特殊原因试图使用视口矩形?
如果您只想让立方体适合它们,最好只更改相机的正交尺寸。

Link to Unity's API on Camera.orthoGraphic size

如果您试图将它们完全贴合到相机的宽度中,则您必须根据宽高比更改正交尺寸。
如果您正试图将它们完全置于高度中,则正交尺寸将为1.

答案 1 :(得分: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;



    }
}
相关问题