using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CoinCounter : MonoBehaviour
{
public int coinCount = 0;
// Update is called once per frame
void Update ()
{
GUIText.text = "x" + coinCount;
}
}
I can't figure out why it is giving me this error.
Replies
Or it might be a mono behaviour so you'll have to add a GUIText component to your object and get a reference to it.
NullReferenceException: Object reference not set to an instance of an object
CoinCounter.Update () (at Assets/Scripts/CoinCounter.cs:12)
using UnityEngine; using System.Collections; using UnityEngine.UI; public class CoinCounter : MonoBehaviour { public int coinCount = 0; Text text; // Update is called once per frame void Update () { text.text = "x" + coinCount; } }What you could do is put public in front of your variable so it becomes visible in the inspector. Then just drag your UI text into it.