繁体   English   中英

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

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

所以我正在统一创建一个简单的 2D 游戏,在某些时候,我遇到了一些错误,我认为这是因为我使用的是旧的写作方式,所以如果有人能给我一种现代的方式来编写 C# 代码这对我很有帮助

这是代码:

    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);
    }
}

以下是错误:

检测 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 () (在 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()

执行命令时出错: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"

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

意外异常 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”。 检查日志中的先前异常 - 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 模块,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 模块,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在 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

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

是的,我知道我还是个初学者很抱歉

尝试去编辑>首选项>外部工具>将您的外部脚本编辑器设置为正确版本的vs,然后单击“重新生成项目文件”按钮。

我不时在我的项目中看到这样的错误,这似乎总是能解决它。

暂无
暂无

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

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