Getting "NullRefrenceException" error in level 2, while displaying score

I tried displaying score but I am getting NullRefrenceException error in level 2 while trying to display the score. But working fine in level 1.
Level 1:-
Level 2:-

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

public class GameStatus : MonoBehaviour {


    [Range(0.1f,10f)] [SerializeField] float GameSpeed = 1f;
    [SerializeField] int PointsPerBlockDestroyed = 10;
    [SerializeField] int CurrentScore=0;
    [SerializeField] TextMeshProUGUI scoreText;

    private void Start()

    // Update is called once per frame
    void Update () {
        Time.timeScale = GameSpeed;

    public void AddToScore()
        CurrentScore += PointsPerBlockDestroyed;
        scoreText.text = "" + CurrentScore.ToString();

Also, blocks are not getting destroyed in level 2. But when I remove scoreText.text = “” + CurrentScore.ToString(); in method public void AddToScore().

Sorry, I just realized i didn’t attached TexMeshPro Text to game status. But still i am curious why blocks were not getting destroyed?

1 Like


If an error is thrown, and you’ve not protected against it, the code execution will typically stop. This may explain why your blocks weren’t being destroyed.

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

Privacy & Terms