首页 > 解决方案 > 在 Unity 中更改分辨率时如何修复黑屏

问题描述

我制作了一个 2d 游戏,在构建它时运行良好,但在我实施分辨率更改后,它无法正确渲染所有内容,仅渲染玩家。

我试过删除这些行,但没有帮助。之后的每个构建都具有该分辨率(我可以看到它被应用于播放器)并且无法渲染其余部分。

我在游戏开始时使用它。

Screen.SetResolution(160, 144, true, 60);

我也得到了这些,但我不确定它们是否相关。

Multiple managers are loaded of type: InputManager
Multiple managers are loaded of type: GraphicsSettings
Multiple managers are loaded of type: PhysicsManager
Multiple managers are loaded of type: QualitySettings
Multiple managers are loaded of type: Physics2DSettings
Multiple managers are loaded of type: VFXManager

标签: c#unity3dscreen-resolution

解决方案


假设您使用的是桌面:

要在桌面平台上设置特定的全屏模式,请使用接受 FullScreenMode 参数的方法重载。

public static void SetResolution(int width, int height, FullScreenMode fullscreenMode, int preferredRefreshRate = 0); 

https://docs.unity3d.com/ScriptReference/Screen.SetResolution.html

fullscreenMode 参数可以是以下类型之一:

ExclusiveFullScreen
FullScreenWindow
MaximizedWindow
Windowed

https://docs.unity3d.com/ScriptReference/FullScreenMode.html

IE:

Screen.SetResolution(160, 144, FullScreenMode.ExclusiveFullscreen, 60); 

推荐阅读