简体   繁体   English

我的 c# 代码在 Unity 中收到很少的错误消息

[英]I'm getting few error message in Unity with my c# code

so I'm creating a simple 2D game in unity and at some point, I'm getting a few errors I think it's because I'm using an old way of writing so if someone can give me a modern way of writing the C# code it will help me very much所以我正在统一创建一个简单的 2D 游戏,在某些时候,我遇到了一些错误,我认为这是因为我使用的是旧的写作方式,所以如果有人能给我一种现代的方式来编写 C# 代码这对我很有帮助

Here is the code:这是代码:

    using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed;

    public Rigidbody2D rb;
    private Vector3 velocity = Vector3.zero;

    void FixedUpdate()
    {
        float horizontalMovement = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;

        MovePlayer(horizontalMovement);
    }

    void MovePlayer(float _horizontalMovement)
    {
        Vector3 targetVelocity = new Vector2(_horizontalMovement, rb.velocity.y);
        rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref velocity, .05f);
    }
}

And here are the errors:以下是错误:

Error detecting Visual Studio installations: System.ComponentModel.Win32Exception (0x80004005): ApplicationName='C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.ide.visualstudio@2.0.12\Editor\VSWhere\vswhere.exe', CommandLine='-prerelease -format json -utf8', CurrentDirectory='', Native error= The system cannot find the file specified.检测 Visual Studio 安装时出错:System.ComponentModel.Win32Exception (0x80004005): ApplicationName='C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.ide.visualstudio@2.0.12\Editor\VSWhere\vswhere .exe', CommandLine='-prerelease -format json -utf8', CurrentDirectory='', Native error= 系统找不到指定的文件。

UnityEngine.Debug:LogError (object) Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor:DiscoverInstallations () (at Library/PackageCache/com.unity.ide.visualstudio@2.0.12/Editor/VisualStudioEditor.cs:59) Microsoft.Unity.VisualStudio.Editor.AsyncOperation`1<Microsoft.Unity.VisualStudio.Editor.IVisualStudioInstallation[]>:b__6_0 (object) (at Library/PackageCache/com.unity.ide.visualstudio@2.0.12/Editor/AsyncOperation.cs:38) System.Threading._ThreadPoolWaitCallback:PerformWaitCallback () UnityEngine.Debug:LogError (object) Microsoft.Unity.VisualStudio.Editor.VisualStudioEditor:DiscoverInstallations () (在 Library/PackageCache/com.unity.ide.visualstudio@2.0.12/Editor/VisualStudioEditor.cs:59) Microsoft.Unity .VisualStudio.Editor.AsyncOperation`1<Microsoft.Unity.VisualStudio.Editor.IVisualStudioInstallation[]>:b__6_0 (object) (在 Library/PackageCache/com.unity.ide.visualstudio@2.0.12/Editor/AsyncOperation.cs: 38) System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()

Error while executing command: C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0.Runtime\hostwin\lld -flavor link /dll /DEBUG /pdb:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\Tom's Adventure\Library\BurstCache\JIT\634edd43564d5aeb45f9bce68c886425.pdb" /noentry /nodefaultlib /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.dll" "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj"执行命令时出错:C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0.Runtime\hostwin\lld -flavor link /dll /DEBUG /pdb:"C:\Users \Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\Tom's Adventure\Library\BurstCache\JIT\634edd43564d5aeb425f9bce68c8 /defaultentry.pdb /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.dll" "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst @1.6.0\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj"

While compiling job: System.Void Unity.Burst.Intrinsics.X86::DoSetCSRTrampoline(System.Int32) at:line 0编译作业时: System.Void Unity.Burst.Intrinsics.X86::DoSetCSRTrampoline(System.Int32) at:line 0

Unexpected exception Burst.Compiler.IL.Aot.AotLinkerException: The native link step failed Error while executing command: C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0.Runtime\hostwin\lld -flavor link /dll /DEBUG /pdb:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\Tom's Adventure\Library\BurstCache\JIT\634edd43564d5aeb45f9bce68c886425.pdb" /noentry /nodefaultlib /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.dll" "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj".意外异常 Burst.Compiler.IL.Aot.AotLinkerException:本机链接步骤失败执行命令时出错:C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0.Runtime\hostwin \lld -flavor link /dll /DEBUG /pdb:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\ Tom's Adventure\Library\BurstCache\JIT\634edd43564d5aeb45f9bce68c886425.pdb" /noentry /nodefaultlib /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c\886"5bce68c886"2C86"4 Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst \burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj”。 Check previous exception in the log - linker command line: "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0.Runtime\hostwin\lld -flavor link /dll /DEBUG /pdb:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\Tom's Adventure\Library\BurstCache\JIT\634edd43564d5aeb45f9bce68c886425.pdb" /noentry /nodefaultlib /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.dll" "C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj"" at Burst.Compiler.IL.Aot.AotNativeLinkBase.RunNativeLinkerTool (System.String command, System.String arguments, System.检查日志中的先前异常 - linker 命令行:“C:\Users\Developers Institute\Tom's Adventure\Library\PackageCache\com.unity.burst@1.6.0.Runtime\hostwin\lld -flavor link /dll /DEBUG / pdb:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.pdb" /pdbaltpath:"C:\Users\Developers Institute\Tom's Adventure\Library\BurstCache\JIT\634edd43564d886aeb245568 .pdb" /noentry /nodefaultlib /out:"C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\634edd43564d5aeb45f9bce68c886425.dll" "C:\Users\Developers Institute\Tom's Adventure\Library\ PackageCache\com.unity.burst@1.6.0\.Runtime\libs\burstRTL_w64.lib" /threads:1 "C:\Users\Developers Institute\Tom's Adventure\Temp\Burst\burst-aotgjyrtly5.re9\lib_burst_generated_part_.obj “”在 Burst.Compiler.IL.Aot.AotNativeLinkBase.RunNativeLinkerTool (System.String 命令,System.String arguments,系统。 String errorMessage, System.String commandType, System.String workingDirectory, System.Boolean muteOutputs) [0x0008b] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Aot.AotNativeLinkLLVMWindows.Link (Burst.Backend.TargetCpu targetCpu, System.Collections.Generic.List'1[T] inputFiles, System.String outputFile, System.Boolean enableDebugInfo) [0x001b0] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Aot.AotCompiler.Link (System.Collections.Generic.List`1[T] groups, System.String nameSuffix, Burst.Compiler.IL.Aot.AotCompilerOptions compilerOptions, System.IO.TextWriter consoleOut, System.IO.TextWriter consoleError) [0x001f8] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.Providers.BaseOnDiskProvider.CommonDiskCompileModule (Burst.Backend.Module module, Burst.Compiler.IL.NativeCompiler String errorMessage, System.String commandType, System.String workingDirectory, System.Boolean muteOutputs) [0x0008b] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Aot.AotNativeLinkLLVMWindows.Link (Burst.Backend.TargetCpu targetCpu, System.Collections .Generic.List'1[T] inputFiles, System.String outputFile, System.Boolean enableDebugInfo) [0x001b0] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Aot.AotCompiler.Link (System.Collections.Generic.List `1[T] groups, System.String nameSuffix, Burst.Compiler.IL.Aot.AotCompilerOptions compilerOptions, System.IO.TextWriter consoleOut, System.IO.TextWriter consoleError) [0x001f8] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler .IL.Jit.Providers.BaseOnDiskProvider.CommonDiskCompileModule(Burst.Backend.Module 模块,Burst.Compiler.IL.NativeCompiler nativeCompiler, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Jit.JitOptions jitOptions, Burst.Compiler.IL.Helpers.Hash128& moduleHash) [0x000b2] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.Providers.OnDiskJitProvider.BeginCompileModule (Burst.Backend.Module module, Burst.Compiler.IL.NativeCompiler nativeCompiler, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Jit.JitOptions jitOptions, Burst.Compiler.IL.Helpers.Hash128& moduleHash, Burst.Compiler.IL.Jit.JitCacheManager jitCacheManager, Burst.Compiler.IL.Jit.GetExternalFunctionPointerDelegate getExternalFunctionPointer, System.Action& invokeBurstInitialize) [0x00000] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.JitCompiler.CompileMethodInternal (Burst.Compiler.IL.Jit.JitResult result, System.Collections.Generic.List'1[T] methodsToCompile, Burst.Compiler.IL.Jit.JitOptions jitOptions) [0x00677] in <685f0c65f2a448a78ba2734aa17d6be3>:0 nativeCompiler, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Jit.JitOptions jitOptions, Burst.Compiler.IL.Helpers.Hash128& moduleHash) [0x000b2] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit .Providers.OnDiskJitProvider.BeginCompileModule(Burst.Backend.Module 模块,Burst.Compiler.IL.NativeCompiler nativeCompiler,Burst.Compiler.IL.NativeCompilerOptions 选项,Burst.Compiler.IL.Jit.JitOptions jitOptions,Burst.Compiler.IL.Helpers .Hash128& moduleHash, Burst.Compiler.IL.Jit.JitCacheManager jitCacheManager, Burst.Compiler.IL.Jit.GetExternalFunctionPointerDelegate getExternalFunctionPointer, System.Action& invokeBurstInitialize) [0x00000] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Comper.JILIT. .CompileMethodInternal (Burst.Compiler.IL.Jit.JitResult 结果, System.Collections.Generic.List'1[T] methodsToCompile, Burst.Compiler.IL.Jit.JitOptions jitOptions) [0x00677] in <685f0c65f2a448a78ba26d at Burst.Compiler.IL.Jit.JitCompiler.CompileMethods (Burst.Compiler.IL.Jit.JitMethodGroupRequest& request, Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00209] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.JitCompiler.CompileMethod (Burst.Compiler.IL.Jit.MethodReferenceWithMethodRefString method, Burst.Compiler.IL.Jit.JitOptions jitOptions, Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00023] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.JitCompilerService+CompilerThreadContext.Compile (Burst.Compiler.IL.Jit.JitCompilerService+CompileJob job, Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00491] in <685f0c65f2a448a78ba2734aa17d6be3>:0在 Burst.Compiler.IL.Jit.JitCompiler.CompileMethods (Burst.Compiler.IL.Jit.JitMethodGroupRequest& 请求,Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00209] 在 <685f0c65f2a448a78ba2734aa17d6be3>:0 在 Burst.Compiler.IL .Jit.JitCompiler.CompileMethod (Burst.Compiler.IL.Jit.MethodReferenceWithMethodRefString 方法, Burst.Compiler.IL.Jit.JitOptions jitOptions, Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00023] in <685f0c65f2a448a78ba2734aa17d6be3>:0 at Burst.Compiler.IL.Jit.JitCompilerService+CompilerThreadContext.Compile (Burst.Compiler.IL.Jit.JitCompilerService+CompileJob 作业,Burst.Compiler.IL.Jit.JitCompilationRequestType requestType) [0x00491] in <685f0c65f2a448a78ba2734aa17d6be3>:0

While compiling job: System.Void Unity.Burst.Intrinsics.X86::DoSetCSRTrampoline(System.Int32) at:line 0编译作业时: System.Void Unity.Burst.Intrinsics.X86::DoSetCSRTrampoline(System.Int32) at:line 0

Yeah I know it's a lot sorry about that I'm still a beginner是的,我知道我还是个初学者很抱歉

Try going to Edit>Preferences>External Tools> Set your External Script editor to the correct version of vs, and then click "Regenerate project Files" button.尝试去编辑>首选项>外部工具>将您的外部脚本编辑器设置为正确版本的vs,然后单击“重新生成项目文件”按钮。

I see errors like this in my projects from time to time, and this almost always seems to fix it.我不时在我的项目中看到这样的错误,这似乎总是能解决它。

暂无
暂无

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

相关问题 我在 Unity 的 C# 代码中不断收到“scriptcs”错误。 我在互联网上看到的任何东西都不起作用 - I keep getting a "scriptcs" error in my C# code for Unity. Nothing I've seen on the internet is working 在我的C#嗅探器中设置套接字选项时,不知道为什么我收到错误代码10022(无效参数) - Don't know why I'm getting Error Code 10022 (Invalid Argument) when setting socket options in my C# sniffer 当我在收件箱中收到新邮件时如何获得通知(使用 IMAP 和 C#)? - How to get notification when I'm getting a new message in my inbox(using IMAP and C#)? 为什么C#代码为什么会不断使Unity崩溃? (我是Unity和C#的初学者) - Why does why C# code keep crashing Unity? (I'm a beginner to Unity and C#) "在我的 C# 代码中,我收到了这种类型的错误" - in my C# code i am getting this type of Error 我想在 c# 2013 中使用我的机器人向频道发送消息和照片,但我收到远程服务器返回错误:(400) 错误请求 - I want to send a message and photo to a channel with my bot in c# 2013, but I'm getting The remote server returned an error: (400) Bad Request 即使我的C#代码正确解析,我仍收到FormatException - I'm getting a FormatException even though my C# code parses correctly 我是 c# 和 unity 的新手,我无法获得基于物理旋转的运动(c# unity) - I'm new at c# and unity and I am having trouble with getting a movement based on rotation with physics(c# unity) 我在我的嵌套类中在属性C#的set函数上得到StackOverflowException错误 - I'm getting StackOverflowException error in my nested class on set function of property C# 不知道为什么我会收到这个 C# 错误 - Not sure why I'm getting this C# error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM