Hey there
In my game, i have serveral global vars (Bools) for checking which points on a map are accessible. Now i would like to do these checks via a script that's attached to the Unity UI.
What would i have to use to let the script check the Vars and how do i use them in an "if" and "else" situation?
Comments
AC.GlobalVariables.GetBooleanValue (int _id);
" inside of an if function.Basically i want to do this if check, and if it is true, i want a hotspot on a map to activate. If it returns false, the hotspot stays turned off.
I can then just do "if (AC.GlobalVariables.GetBooleanValue(0) == false)" and it works perfectly! Thanks a lot!
There is one more thing i noticed, and it's that Unity always spits out a debug message, saying "Variable with ID=0 not found!", yet the script which references that variable works fine and gets/sets it just fine
Do i need to initialize the variable anywhere the script?
I tried putting "bool WeMetGoal = AC.GlobalVariables.GetBooleanValue (0);" right after the "public class", but that gives me an error:
"Load is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead."
However when i do call it in Start, i cannot use "WeMetGoal" in OnEnabled, which i need to let the UI check if a variable changed since the last time i opened the UI..
Here's the script, perhaps there really is something wrong with it.. http://paste.ofcode.org/qnDZ9bm6QzP82BinSNgTXn
I still constantly get the error
"Load is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'ShowDossierKeys' on game object 'BTN_LB1_UI_NB_Dossier_PortraitGrid_5'.
See "Script Serialization" page in the Unity Manual for further details."
You need to initialise the var in a function - as the error is telling you - but you also need to initialise it at the time you need to check it, since the AC Global Variable will have changed since the game starts and whenever you run that function.