【问题标题】:Unity3D Can you set the camera view width and height?Unity3D可以设置相机视图的宽度和高度吗?
【发布时间】:2016-12-23 15:01:49
【问题描述】:

我正在尝试将我的相机固定为正方形而不是矩形,因为我目前正在开发 2d 游戏。我希望将相机设置为正方形,而不是设置为默认值的普通矩形。是否有任何可能的方法来更改这些值?

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    您可以通过更改Camera 的视口rect 来做到这一点。

    float bevel = 0F;
    if (Screen.width > Screen.height)
    {
      bevel = 0.5F * ((float)(Screen.width - Screen.height) / (float)Screen.width);
      cam.rect = new Rect(bevel, 0F, 1F - 2F*bevel, 1F);
    }
    else
    {
      bevel = 0.5F * ((float)(Screen.height - Screen.width) / (float)Screen.height);
      cam.rect = new Rect(0F, bevel, 1F, 1F- 2F*bevel);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      • 2012-03-01
      相关资源
      最近更新 更多