I have created a Unity script which changes multiple text's every frame. Now I've dragged it onto the script, and everything is working. But when I drag the script onto the EventSystem and Drag and Drop the Text onto it, there is an error "Object Reference not set to an instance of an object". How can I fix it: Here is the script:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class textChange : MonoBehaviour
{
public TextMeshProUGUI text;
//public Text costTxt;
public TextMeshProUGUI addTxt;
public int coins;
public int costs;
void Start()
{
text = GetComponent<TextMeshProUGUI>();
//costTxt = GetComponent<Text>();
addTxt = GetComponent<TextMeshProUGUI>();
}
Update is called once per frame
void Update()
{
coins = Mathf.RoundToInt(PlayerPrefs.GetFloat("coins"));
text.text = "$ " + coins.ToString();
//costTxt.text = Mathf.RoundToInt(PlayerPrefs.GetFloat("cost")).ToString();
addTxt.text = Mathf.RoundToInt(PlayerPrefs.GetFloat("add")).ToString();
}
}