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

Unity构建游戏时反复抛出CS0246错误求助

Unity编译错误:找不到PenStatus类型的解决办法

报错信息:

Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\EventData\PointerEventData.cs(235,16): error CS0246: The type or namespace name 'PenStatus' could not be found (are you missing a using directive or an assembly reference?)
Library\PackageCache\com.unity.ugui@1.0.0\Runtime\EventSystem\UIElements\PanelEventHandler.cs(391,20): error CS0246: The type or namespace name 'PenStatus' could not be found (are you missing a using directive or an assembly reference?)
Error building Player because scripts had compiler errors
Build completed with a result of 'Failed' in 51 seconds (51127 ms)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)ds.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002da] in :0
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in :0
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

解决步骤:

  • 检查Unity版本与UGUI包兼容性:PenStatus是Unity 2022.x及以上版本引入的类型,若使用旧版本引擎,UGUI包版本可能不匹配。打开Package Manager,找到com.unity.ugui,切换到与当前引擎匹配的版本。
  • 重建UGUI缓存:删除项目目录下的Library/PackageCache/com.unity.ugui@1.0.0文件夹,重启Unity,让引擎自动重新下载并导入正确的UGUI包文件。
  • 验证平台输入模块:打开Unity Hub,找到当前使用的Unity版本,点击右侧三个点→添加模块,检查是否勾选了对应平台的笔/触控支持模块(比如Windows平台的「Windows Pen and Touch Support」),该类型依赖这些模块。
  • 重置项目设置:在编辑器中依次点击Edit → Project Settings → Editor,找到「Reset All Settings」选项,重置后重新尝试构建。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 11:10:23