【问题标题】:Unity - error building Player because scripts have compile errors in the editorUnity - 错误构建播放器,因为脚本在编辑器中有编译错误
【发布时间】:2020-08-24 02:16:11
【问题描述】:

尝试在 Web GL 中构建统一项目时遇到问题。我目前正在使用统一操场脚本+我自己设计的两个。这是我的脚本,谁能告诉我问题出在哪里/哪里?谢谢!

Error:UnityEditor.BuildPlayerWindow+BuildMethodException: 构建播放器时出错,因为脚本在编辑器中有编译错误 在 UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer(UnityEditor.BuildPlayerOptions 选项)[0x002bb] 在 :0 在 UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] 在 :0 UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

我的脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour
{
    public void PlayGame()
    {
        SceneManager.LoadScene("Game");
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour { 

    private Rigidbody2D rb;

    private bool isGrounded;

    public Transform feetPos;

    public float checkRadius, jumpForce, moveInput, speed, jumpTimeCounter,jumpTime;

    public LayerMask whatIsGround;
    private bool isJumping;
    private Animator anim;
    // Start is called before the first frame update
    void Start()
    {
        anim = GetComponent<Animator>();
        rb = GetComponent<Rigidbody2D>();
    }
    private void FixedUpdate()
    {
        moveInput = Input.GetAxisRaw("Horizontal");
        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
    }

    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics2D.OverlapCircle(feetPos.position, checkRadius, whatIsGround);
        if(moveInput == 0)
        {
            anim.SetBool("isRunning",false);
        }
        else
        {
            anim.SetBool("isRunning", true);
        }
        if (moveInput > 0)
        {
            transform.eulerAngles = new Vector3(0, 0, 0);
        }else if(moveInput < 0)
        {
            transform.eulerAngles = new Vector3(0, 180, 0);
        }

        if(isGrounded == true && Input.GetKeyDown(KeyCode.Space))
         {
            isJumping = true;
            jumpTimeCounter = jumpTime;
            rb.velocity = Vector2.up * jumpForce;
        }
        if (Input.GetKey(KeyCode.Space) && isJumping==true)
        {
            if (jumpTimeCounter > 0)
            {
              rb.velocity = Vector2.up * jumpForce;
                jumpTimeCounter -= Time.deltaTime;
            }
            else
            {
                isJumping = false;
            }

        }
        if (Input.GetKeyUp(KeyCode.Space))
        {
            isJumping = false;
        }
    }
}

【问题讨论】:

  • 您的格式到处都是,并且该错误表明很可能是语法错误或缺少导入/类型错误-您使用的是 IDE 吗?如果不是,你应该是,它会立即突出这样的问题。无论哪种方式,这个错误都是一种症状,而不是原因 - 您应该在编辑器中也出现其他错误,首先解决这些错误,这个错误就会消失。
  • 我使用的是 Microsoft Visual Studio,但 IDE 没有显示任何错误。
  • 提示:在 Visual Studio 中按 Ctrl+K,然后按 Ctrl+D。一致的代码是可读的代码。除此之外,错误清楚地表明 脚本有编译错误,这些编译错误应该在输出区域中显示为单独的错误。这些才是真正的问题。
  • 我将再次进一步查看代码,感谢您的快速帮助!

标签: c# unity3d


【解决方案1】:

已修复:问题不在我的代码中,但我必须删除 XR Legacy Input Helpers 包才能构建游戏!您可以转到 Window > Package Manager,向下滚动到 XR Legacy Input Helpers,选择它并单击 Remove。

【讨论】:

    猜你喜欢
    • 2020-09-01
    • 1970-01-01
    • 2017-07-24
    • 2018-03-21
    • 2018-03-13
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多