Hey again
I'm slowly getting into learning how to use AC within scripts, but now i have encountered an error that doesn't really make sense to me. I use the following script:
public class WhereCanWeGo : MonoBehaviour {
AC.MenuElement XXXMarker = AC.PlayerMenus.GetElementWithName("NotebookMap","GoToXXX");
void OnEnable () {
if (AC.GlobalVariables.GetBooleanValue(0) == true){
XXXMarker.isVisible = true;
AC.KickStarter.playerMenus.RecalculateAll ();
}
else if (AC.GlobalVariables.GetBooleanValue(0) == false){
XXXMarker.isVisible = false;
AC.KickStarter.playerMenus.RecalculateAll ();
}
}
}
Unity is now giving me an error:
"NullReferenceException: Object reference not set to an instance of an object WhereCanWeGo.OnEnable () (at Assets/LB1.1/Scripts/WhereCanWeGo.cs:16)".
Same error happens for line 12, so always for the "isVisible" lines.
Comments
private void OnEnable ()
{
EventManager.OnMenuTurnOn += OnMenuTurnOn;
}
private void OnDisable ()
{
EventManager.OnMenuTurnOn -= OnMenuTurnOn;
}
private void OnMenuTurnOn (AC.Menu _menu, bool isInstant)
{
Debug.Log ("The Menu " + _menu.title + " was turned on.");
}
However i have one more question.. When i post that code into my script, it does not to anything, not even the debug message shows up.. Do i have to tell the script which AC menu we turn on/off? And if so, how would i do that? I have tried changing "_menu" to the actual menu name, but that did not work
I have also tried placing it into the UI itself, not the button, but nothing happens.
"NullReferenceException: Object reference not set to an instance of an object"
which does
"GridName = GameObject.Find ("CNV_LB1_UI_NB_Dossier/GRD_LB1_UI_NB_Dossier_PortraitGrid/BTN_LB1_UI_NB_Dossier_PortraitGrid_5/LBL_LB1_UI_NB_Dossier_PortraitGrid_5").GetComponent<Text> ();"
I have also noticed that, when i remove that line, the debug text does indeed show, but the script seems to be running even after i closed the UI, which is sub-optimal, since we do not need to have it running all the time during gameplay, but only when we really need it (i.e. when we open the UI)
bool WeMetKeys = AC.GlobalVariables.GetBooleanValue (1);
if (WeMetKeys == true) {
Debug.Log ("This works, but the next function does not.");
KeysGridName.text = "Keys";
}
Those are within the OnMenuTurnOn, and the debug message shows, however it does not execute any other things (Like setting the text to "Keys"). The text object itself i have set in the editor (it's a public), however even when it was set to private and i told it where exactly the label is located it did not go past the Debug message..
Error message is still roughly the same:
NullReferenceException: Object reference not set to an instance of an object
WeMetKeysNow.OnMenuTurnOn (AC.Menu _menu, Boolean isInstant) (at Assets/WeMetKeysNow.cs:32)
Line 32 is the keys.text one
If you're getting the Debug log, the AC side of your script is working - the rest should be down to general coding.
KeysGridName = GameObject.Find ("CNV_LB1_UI_NB_Dossier/GRD_LB1_UI_NB_Dossier_PortraitGrid/BTN_LB1_UI_NB_Dossier_PortraitGrid_5/LBL_LB1_UI_NB_Dossier_PortraitGrid_5").GetComponent<Text> ();
And that caused that same error, too.
AC Simply calls the menu up prefab currently, everything else is done via scripts.
All the scirpt is supposed to is check an AC var (WeMetKeys) to check if we did or did not meet him, and if we did, switch out a button's images and set a text label from "Unknown" to "Keys".