【问题标题】:Every C# script is throwing errors on the console每个 C# 脚本都在控制台上抛出错误
【发布时间】:2021-01-28 15:08:32
【问题描述】:

我刚刚创建了一个全新安装的 Unity 项目,还创建了一个 C# 脚本并附加到一个 3D 游戏对象(立方体),但是当我双击打开脚本时,它立即显示:

Exception thrown while invoking [OnOpenAssetAttribute] method 'Unity.CodeEditor.CodeEditor:OnOpenAsset (int,int,int)' : InvalidOperationException: Cannot start process because a file name has not been provided.
System.Diagnostics.Process.Start () (at <d465e2b2e5054d2787d6364114c43446>:0)
(wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
UnityEditor.DefaultExternalCodeEditor.OpenProject (System.String path, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/DefaultExternalCodeEditor.cs:96)
Unity.CodeEditor.CodeEditor.OnOpenAsset (System.Int32 instanceID, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/CodeEditor.cs:56)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

InvalidOperationException: Cannot start process because a file name has not been provided.
System.Diagnostics.Process.Start () (at <d465e2b2e5054d2787d6364114c43446>:0)
(wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
UnityEditor.DefaultExternalCodeEditor.OpenProject (System.String path, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/DefaultExternalCodeEditor.cs:96)
Unity.CodeEditor.CodeEditor.OpenFileAtLineColumn (System.String path, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/CodeEditor.cs:31)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

例如,如果我尝试在脚本中使用Debug.Log,它会显示

'Debug' does not contain a definition for 'Log'

没有任何作用。

我已经尝试重新打开 unity,创建另一个项目,安装另一个版本(我现在使用的是最新的 2019.2.0b1)并且这种情况总是发生,我使用的是 Visual Studio,并且在 Unity 中提示错误控制台。

【问题讨论】:

  • 您好,您可以编辑您的帖子并向我们展示您的 C# 代码吗?谢谢!
  • 您是否在 Visual Studio 中安装了 Unity for Visual Studio Tools 扩展,并且在 Unity 首选项中选择了 Visual Studio 作为您的编辑器?当 Unity 感到困惑并且不明白我想使用 Visual Studio 而不是 Rider 作为我的编辑器时,我看到了这个错误。
  • 您好,关于我的代码,这是您创建脚本时的默认代码,我认为 Unity 在某种程度上像@RetiredNinja 所说的那样感到困惑。我是 Unity 新手,所以我刚刚安装了 Unity Hub 并选择安装 Visual Studio,仅此而已。如何检查我是否有 Visual Studio 工具扩展?我认为 Visual Studio 是默认的,因为我只需双击脚本图标并打开 VS。
  • @RetiredNinja 这是编辑器的原因,它没有默认设置为 Visual Studio,我已经更改,现在它工作得很好。谢谢!
  • This link will show you how to change the default script editor in Unity. 对 OP 有效的方法也对我有效,更改了默认脚本编辑器。 (在答案中回复此链接而不是评论,因为我无法发表评论)

标签: c# unity3d


【解决方案1】:

正如评论区有人所说,解决方案是将 Visual Studio 设置为 Unity 的默认编辑器。

【讨论】:

    【解决方案2】:

    您是否安装了正确的 .net 框架?尝试安装最新的。如果您已经尝试过重新安装 Unity,我唯一能想到的就是它。

    【讨论】:

    • @DiegoVinicius 我很确定它确实如此,但就像我说的那样,这是我能想到的唯一其他事情。
    【解决方案3】:

    只是一种预感。尝试使用 Visual Studio 2017 并查看是否遇到相同的错误。安装 Unity Visual Studio 时,它建议使用 2017 版本。我想他们可能还没有完全支持 VS 2019。正如我所说,只是一种预感,但值得一试。

    编辑:刚刚意识到“2019”部分可能是 Unity 版本,但如果不是,请尝试上述 :-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 1970-01-01
      • 2016-12-13
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      相关资源
      最近更新 更多