Hello,
I created a button “Plus” and wanted to assign onClick function but it was returning “string name” only, not other methods. I found a solution to this: created empty object EmptyGameObject, attached the script “TestManager” to it, then attached the object instead of the script to the onClick field and got access to my method “increase”. But when running the game I get two errors:
NullReferenceException: Object reference not set to an instance of an object
TestManager.Update () (at Assets/TestManager.cs:25)
NullReferenceException: Object reference not set to an instance of an object
TestManager.Increase () (at Assets/TestManager.cs:30)
I know that both are referring to and highlighting the EmptyGameObject but I’m not sure what to do there.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestManager : MonoBehaviour {
public static TestManager instance;
public Text gameScoreText;
private int gameScore;
// Use this for initialization
void Start () {
gameScore = 0;
}
// Update is called once per frame
void Update () {
gameScoreText.text = gameScore.ToString ();
}
public void Increase (){
gameScore++;
}
}
Any help would be appreciated!