I am using Unity 2018.2.14f1
I have verified that I have the Text object created under my Canvas
I have deleted my code and copy and pasted in the code from the course
My score will not update.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreDisplay : MonoBehaviour
{
Text scoreText;
GameSession gameSession;
// Use this for initialization
void Start()
{
scoreText = GetComponent<Text>();
gameSession = FindObjectOfType<GameSession>();
Debug.Log(GetComponent<Text>().name);
}
// Update is called once per frame
void Update()
{
scoreText.text = gameSession.GetScore().ToString();
}
}
Yet when I run this my Text stays set to 0 and I get this message
NullReferenceException: Object reference not set to an instance of an object
ScoreDisplay.Start () (at Assets/Scripts/ScoreDisplay.cs:18)
Then on update
NullReferenceException: Object reference not set to an instance of an object
ScoreDisplay.Update () (at Assets/Scripts/ScoreDisplay.cs:24)
When I try logging the scoreText instead of coming back as an object it comes back as null.
I have deleted and recreated the
UI->Text component several times and it keeps giving me the same error.
My source code for this is view-able here