NullReferenceException

Hi i am getting this error with the scoretext on the game over screen unsure how to fix it.

NullReferenceException: Object reference not set to an instance of an object
UIGameOver.Start () (at Assets/Scripts/UIGameOver.cs:18)

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using TMPro;

public class UIGameOver : MonoBehaviour

{

[SerializeField] TextMeshProUGUI scoreText;

ScoreKeeper scoreKeeper;

void Awake()

{

    scoreKeeper = FindObjectOfType<ScoreKeeper>();

}

void Start()

{

    scoreText.text = "You Scored:\n" + scoreKeeper.GetScore();

}

}

Hi,

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If scoreText is null, check if there is a ScoreKeeper component in your current scene.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms