0

I have a problem when trying to build a unity project in Web GL. I am currently using the unity playground script + two of my own design. Here's my script, can anybody tell me what/where the problem is? Thank you!

Error:UnityEditor.BuildPlayerWindow+BuildMethodException: Error building Player because scripts have compile errors in the editor 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)

My scripts:

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;
        }
    }
}
4
  • Your formatting is all over the place, and that error indicates most likely a syntax error or missing import/type error - are you using an IDE? If not, you should be, it will instantly highlight problems like that. Either way, this error is a symptom, not a cause - you should have other errors showing up in the editor too, address those first and this one will go away. Commented May 8, 2020 at 13:48
  • I am using Microsoft Visual Studio, but the IDE doesn't show any errors. Commented May 8, 2020 at 13:53
  • Tip for you: Hit Ctrl+K, then Ctrl+D in Visual Studio. Consistent code is readable code. That aside, the error clearly says the scripts have compile errors, those compile errors should be showing up as separate errors in the output area. Those are the actual problem. Commented May 8, 2020 at 13:56
  • I will take a further look into the code once again, thank you for the quick help! Commented May 8, 2020 at 13:58

1 Answer 1

1

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 it and click Remove.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.