NullReferenceException: Object reference not set to an instance of an object at StatDisplay.
I don’t know why even I copy and paste lecture code but it shows that error.
It shows on especially
private void UpdateDisplay () {
starText.text =stars.ToString();
}
for this sentence.
I attached script to LevelCanvas-Stars with text
I almost give up for this issue…
If there are any body to let me know… Please…
My code for star display
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent (typeof(Text))]
public class StarDisplay : MonoBehaviour {
public Text starText;
public int stars = 100;
public enum Status {SUCCESS, FAILURE};
// Use this for initialization
void Start () {
starText = GetComponent <Text> ();
UpdateDisplay();
}
public void AddStars (int amount) {
stars += amount;
UpdateDisplay();
}
public Status UseStars (int amount) {
if (stars >= amount) {
stars -= amount;
UpdateDisplay();
return Status.SUCCESS;
}
return Status.FAILURE;
}
public void UpdateDisplay () {
starText.text =stars.ToString();
//Debug.Log("Stars : "+ stars.ToString()) ;
}
}