Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question i can't launch my game in webgl

Discussion in 'Editor & General Support' started by EliaxDev, Jun 21, 2023.

  1. EliaxDev

    EliaxDev

    Joined:
    Jun 21, 2023
    Posts:
    1
    Hi unity community,when i try my unity game in my bowser it shows this message:

    An error occurred running the unity content on this
    page.see your browser javascript console for more info
    the error was:abort(165) at error

    and after that when it changes the scene,the screen of my game just got freeze,
    looking in my unity project of the game in the console it shows this message:
    NullReferenceException: Object reference not set to an instance of an object
    Player.UpdateCharacter (System.Int32 selectedOption) (at Assets/Scripts/Player.cs:43)
    Player.Start () (at Assets/Scripts/Player.cs:24)

    i think the problem is in the player,more specific the player script i use for the character when it moves
    here is the script i use for my character:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;

    public class Player : MonoBehaviour
    {
    public float playerSpeed;
    private Rigidbody2D rb;
    private Vector2 playerDirection;

    public CharacterDatabase characterDB;
    public Text nameText;
    public SpriteRenderer artworkSprite;

    private int selectedOption = 0;

    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent<Rigidbody2D>();
    LoadSelectedOption();
    UpdateCharacter(selectedOption);
    }

    // Update is called once per frame
    void Update()
    {
    float directionY = Input.GetAxisRaw("Vertical");
    playerDirection = new Vector2(0, directionY).normalized;
    }

    void FixedUpdate()
    {
    rb.velocity = new Vector2(0, playerDirection.y * playerSpeed);
    }

    private void UpdateCharacter(int selectedOption)
    {
    Character character = characterDB.GetCharacter(selectedOption);
    artworkSprite.sprite = character.characterSprite;
    nameText.text = character.characterName;
    }

    private void LoadSelectedOption()
    {
    if (!PlayerPrefs.HasKey("SelectedOption"))
    {
    selectedOption = 0;
    }
    else
    {
    selectedOption = PlayerPrefs.GetInt("SelectedOption");
    }
    }
    }

    please i need really help i was triying some hours to fix this and i dont get fix anything :(
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    37,255
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,394
    Does it work in the editor?

    In any case, the error is in line 43:
    Assets/Scripts/Player.cs:43

    Try to think of reasons why whatever object on that line (we can't tell because you didn't use code tags) may be null. If it happens in playmode too, attach the debugger of the IDE you are using and set a breakpoint.