- Home /
Unity UI issues
Before anything else, I tried posting this in the correct category on the forums, but for whatever reason theres no option to post a new thread even tho I have done so before??
Anyways.
So I'm creating a simple "menu" to buy and sell things. I have started with the complete basics, and just started off by making a very very simple interface. It shows you how much money you currently have, and the option to "add 5"
I can get it to where it will show my current amount, but I keep getting this error:
NullReferenceException: Object reference not set to an instance of an object
GM.Start () (at Assets/Scripts/GM.cs:12)
Heres a picture of my setup + the C# code I'm working on
Can someone please help me out? I've been stuck on this a lot longer than I've wanted to be...
CODE: using UnityEngine; using UnityEngine.UI; using System.Collections;
public class GM : MonoBehaviour
{
public int startMoney = 100;
public int addAmount = 5;
public Text currentMoney;
void Start ()
{
currentMoney.text = startMoney.ToString ();
}
void Update ()
{
}
void OnBuy ()
{
currentMoney.text = startMoney + addAmount.ToString ();
}
}
new1.png
(34.9 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612084224im_/https://answers.unity.com/themes/thub/images/avi.jpg)