You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity中GUI.Label无法正常工作?附构建错误与代码求助

构建错误解析

Internal build system error. BuildProgram exited with code -2146233088.
error: Build path contains project built with "Create Visual Studio Solution" option, which is incompatible with current build settings. Consider building your project into an empty directory.
System.Exception: Build path contains project built with "Create Visual Studio Solution" option, which is incompatible with current build settings. Consider building your project into an empty directory.
at WinPlayerBuildProgram.WinPlayerPrerequisiteChecks.CheckSafeProjectOverwrite(PlayerBuildConfig playerBuildConfig)
at WinPlayerBuildProgram.WinPlayerBuildProgram..ctor(String[] args)
at PlayerBuildProgramTypeWrapper.Run(String[] args)
at Program.Main(String[] args)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()

这个错误的核心原因是:当前指定的构建目录中,存在之前用「Create Visual Studio Solution」选项构建生成的文件,这类文件和当前构建设置不兼容。Unity不允许在同一目录下混合两种不同构建模式的产物,解决方法:

  • 清空当前构建目录的所有内容后重新构建
  • 更换一个全新的空目录作为构建输出路径
OnGUI代码问题

你提供的OnGUI代码存在两处问题:

void OnGUI()
{
    GUI.Label(new Rect(-0.5f, 0.5f, -0.5f, 0.5f), "lol");
}
  1. Rect的宽高参数错误:把宽度和高度设为了负数(-0.5f),Rect的宽高必须是正数,否则控件无法正常渲染。
  2. 坐标超出屏幕范围:OnGUI使用屏幕像素坐标,负数坐标会让控件跑到屏幕可视区域外,导致看不到。

修改后的代码示例:

void OnGUI()
{
    GUI.Label(new Rect(50, 50, 100, 20), "lol");
}

修改后标签会显示在屏幕左上角(50,50)的位置,宽100像素、高20像素的区域内。

内容的提问来源于stack exchange,提问作者mataldin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 12:10:29