繁体   English   中英

Unity - 错误构建播放器,因为脚本在编辑器中有编译错误

[英]Unity - error building Player because scripts have compile errors in the editor

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

错误:UnityEditor.BuildPlayerWindow+BuildMethodException:构建播放器时出错,因为脚本在 UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer 编辑器中存在编译错误(UnityEditor.BuildPlayerOptions 选项)[0x002bb] in <90d4bcb003fb405fb09241aed2f178aa>:0 在 UnityEditor.BuildPlayerWindow.CallBuildMethods(系统.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <90d4bcb003fb405fb09241aed2f178aa>: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;
        }
    }
}

Fixed it: The problem was not in my code, but I had to remove the XR Legacy Input Helpers package in order for the game to build, You can do that by going to Window > Package Manager, scroll down to XR Legacy Input Helpers. select 并单击删除。

暂无
暂无

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

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