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

问题描述 投票:0回答:1

我在尝试用Web GL搭建unity项目时遇到了一个问题。我目前使用的是unity playground脚本+两个我自己设计的脚本。这是我的脚本,谁能告诉我问题出在哪里?谢谢大家

错误:UnityEditor.BuildPlayerWindow+BuildMethodException: 在UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002bb] in <90d4bcb003fb405fb09241aed2f178aa>:0 at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002bb] in <90d4bcb003fb405fb09241aed2f178aa>:0 at UnityEditor. BuildPlayerWindow.CallBuildMethods (System.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;
        }
    }
}
c# unity3d
1个回答
0
投票

修复了。问题不在我的代码里,而是我必须删除XR传统输入助手包,才能让游戏建立起来! 你可以通过进入Window > Package Manager,向下滚动到XR Legacy Input Helpers,选择它并点击Remove。

© www.soinside.com 2019 - 2024. All rights reserved.