I followed in q and a nina’s help in there but still not working
prtsc/f11 broken
Game score:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameScore : MonoBehaviour
{
int score = 1;
private void Awake()
{
SetUpSingleton();
}
private void SetUpSingleton()
{
int numberOfGameSessions = FindObjectsOfType<GameScore>().Length;
if (numberOfGameSessions > 1)
{
Destroy(gameObject);
}
else
{
DontDestroyOnLoad(gameObject);
}
}
public int GetScore()
{
return score;
}
public void AddToScore(int scoreValue)
{
score += scoreValue;
}
public void ResetGame()
{
gameObject.SetActive(false);
Destroy(gameObject);
}
}
Score Display:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreDisplay : MonoBehaviour
{
Text scoreText;
GameScore score;
// Start is called before the first frame update
void Start()
{
scoreText = GetComponent<Text>();
score = FindObjectOfType<GameScore>();
}
// Update is called once per frame
void Update()
{
scoreText.text = score.GetScore().ToString();
}
}
ERROR:
NullReferenceException: Object reference not set to an instance of an object
Thank you!!!