- Home /
Question by
Nick123451 · Oct 11, 2021 at 01:39 AM ·
functionbooleanif-statementspropertiesupdate function
Check a boolean function without using Update()
I want to check if a bool function is true or false, but I wanna avoid the Update function. I've looked into properties but I could only find stuff for bool variables not bool functions. There becomes the problem of assigning Win() = value; in the property that doesn't work since it's a method, maybe there is a trick to it, any help is appreciated.
bool Win()
{
foreach (GameObject letter in wordUI.playerLetters)
{
if (!letter.GetComponentInChildren<TextMeshProUGUI>().enabled) return false;
}
return true;
}
Currently checking constantly in the Update function works but I know it's a terrible idea.
void Update()
{
if (Win()) currentState = State.WIN;
}
Comment
Answer by Rechronicle · Oct 11, 2021 at 05:23 AM
Use UnityEvent or Event to check if you win the game. So you don't have to check the condition in every frame.