【问题标题】:How to lock screen ratio? Unity2d如何锁定屏幕比例? Unity2d
【发布时间】:2023-01-19 07:36:14
【问题描述】:

我开始在 Unity 上开发一个 2D 平台游戏,我需要玩家只看到 16:9 比例的东西,多余的东西用黑条覆盖。

Only what is in the white frame should be rendered.

But when building on my phone with a wide resolution, there is extra view on the sides

为此,我只是在用户界面上制作了通常的黑条,但是对于这个问题有更实际的解决方案吗?

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    因为每部手机都有自己的分辨率,所以您需要编写脚本来处理这些更改。

    You can look at this video 已经写好的脚本和完整的解释。

    【讨论】:

    • 我的问题不在于此视频中的 UI。我需要游戏的分辨率在任何设备上都相同(即,超过所需值的地方会出现黑条)。但感谢您的回复。
    【解决方案2】:
    using UnityEngine;
    
    public class Setaspec : MonoBehaviour
    {
        Camera camera;
        public float width;
        public float height;
        public float zoom;
    
        private void Start() {
            camera = GetComponent<Camera>();
            if (zoom > 0) {
                float scaling = (camera.orthographicSize*zoom);
                float fovScale = (camera.fieldOfView * zoom);
    
                camera.orthographicSize = scaling;
                camera.fieldOfView = fovScale;
                
            }
        }
        void Update()
        {
            camera.aspect = width/height;
        }
    }
    

    但是,这不会添加黑条,而是会重新缩放视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-15
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多