Hi,
I’ve set a public GameObject of type Text. Dragged and dropped the Text UI into this GameObject.
I have a button that then invokes a UnityAction, but when it enters that function (TestModalPanel.cs: TestOkFunction()), it can’t find the Text, giving a NullReferenceException.
Does public GameObjects not get passed when you invoke an event? But this doesn’t seem to be the case when I stored a bunch of Textures (see TestModalPanel.cs, TestYesFunction())
NullReferenceException: Object reference not set to an instance of an object
TestModalPanel.TestOkFunction () (at Assets/Scripts/TestModalPanel.cs:91)
UnityEngine.Events.InvokableCall.Invoke (System.Object[ ] args)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[ ] parameters)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[ ] parameters)
UnityEngine.Events.UnityEvent.Invoke ()
UnityEngine.UI.Button.Press ()
public Text coins;
void TestOkFunction() {
Debug.Assert (coins != null, “Text Coins can’t be null. Assign a GameObject.”);
//if (coins != null)
{
numCoins += 100;
coins.text = “100 coins”;
}
}
I have my project uploaded to GitHub: GitHub - elissatong/UnityGenericModal: Unity GUI based generic modal window
Greatly appreciate any help you can give.
Thanks
2248415–150187–TestModalPanel.cs (2.46 KB)
2248415–150188–ModalPanel.cs (2.32 KB)
