简体   繁体   English

每个 C# 脚本都会在控制台上抛出错误

[英]Every C# script is throwing errors on the console

I've just created an Unity project with a clean installation, also created a C# script and attached to a 3D Game Object (Cube), but when I double-click to open the script it instantly says:我刚刚创建了一个全新安装的 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)

and

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)

And if I, for example, try to use Debug.Log in the script, it says例如,如果我尝试在脚本中使用Debug.Log ,它会说

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

Nothing works.什么都行不通。

I've already tried to reopen unity, create another project, install another version (I'm now using the latest 2019.2.0b1) and this always happens, I'm using Visual Studio and the errors are prompted in the Unity console.我已经尝试重新打开 Unity,创建另一个项目,安装另一个版本(我现在使用的是最新的 2019.2.0b1),这总是发生,我使用的是 Visual Studio,并且在 Unity 控制台中提示错误。

解决方案是将 Visual Studio 设置为 Unity 的默认编辑器,正如评论部分中的某个人所说。

Do you have the correct .net frameworks installed?您是否安装了正确的 .net 框架? Try and install the latest ones.尝试安装最新的。 Its the only thing I can think of if you've already tried reinstall Unity.如果您已经尝试重新安装 Unity,我唯一能想到的就是它。

Just a hunch.只是一种预感。 Try use Visual Studio 2017 and see if you get the same error.尝试使用 Visual Studio 2017 并查看是否出现相同的错误。 When installing Unity the Visual Studio it suggests is the 2017 version.安装 Unity 时,Visual Studio 建议使用 2017 版本。 I imagine they may not yet support VS 2019 fully.我想他们可能还没有完全支持 VS 2019。 As I said, just a hunch, but worth trying.正如我所说,只是一种预感,但值得一试。

EDIT: Just realized the "2019" part was likely Unity version, but if not, try the mentioned :-)编辑:刚刚意识到“2019”部分可能是 Unity 版本,但如果不是,请尝试提到的 :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM