I have been trying to do a score counter in unity2d using textmeshpro recently yet I have became stuck with an error of: NullReferenceException: Object reference not set to an instance of an object
Score.Update () (at Assets/Scripting/Score.cs:22). I have been stuck on this for 3 hours now, does anyone know anything to help? Thanks in advance!
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Score : MonoBehaviour
{
public TextMeshProUGUI ScoreText;
int ScoreCount = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Ui Components
ScoreCount = ScoreCount + (int)Player.Speed * (int)Time.deltaTime;
ScoreText.text = ScoreCount.ToString();
//this code is the error ^
}
}