C# Update Function Question

I am trying to set a bool component from another C# script from false to true from an update function when the int is greater than a specific number. My problem is that since update calls every frame the bool is constantly made true and can no longer be made false later on. I feel like I’ve probably missed something super obvious? I think I need to have it in the update function because it needs to be able to check "sphereNo"s value which is always changing. The only time it will go back to false is when I make sphereNo less than 5. Any help would be much appreciated, thanks!

       void Update () {
			if (sphereNo > 5 && popupScript.showPopUp == false) {
				popupScript.showPopUp = true;
				popupScript.PopTitle = "WARNING:";
				popupScript.PopText = "text";
				popupScript.ToVisit = "sphere2";
			}
	       }
        }

Gotcha! I’m still missing one thing though. If you want it to be called once, why do you need to set it to true again? Does another script rely on it being true?

If your answer is yes, then I have your solution. You need two bools. One bool that the other script relies on, and one that is declared within this script.

PS. “!bool” is the same, and faster than “bool == false”. Its good practice ;D

void Update () 
{
             if (sphereNo > 5 && !newBoolCalled) 
             {
                 newBoolCalled = true;
                 popupScript.showPopUp = true;
                 popupScript.PopTitle = "WARNING:";
                 popupScript.PopText = "text";
                 popupScript.ToVisit = "sphere2";
             }
}

If your answer is no. Then the solution is: don’t set it to true again.

void Update () 
{
             if (sphereNo > 5 && !popupScript.showPopUp) 
             {
                 popupScript.PopTitle = "WARNING:";
                 popupScript.PopText = "text";
                 popupScript.ToVisit = "sphere2";
             }
}

sphereNo is an integer that increases by 1 every frame in a separate script. I want 'showPopUp to = true when sphereNo’s value is greater than 5 so a GUI box will pop up and warn the player. At the moment I have all of my scripts on a script manager gameobject if that makes a difference. I just dont understand how to get sphereNo = true; to be called once when sphereNo passes 5 and then not call it again each frame.

You should probably set showPopUp to true in the script/function where you increment sphereNo, There is no need to check the value every frame if you know exactly where it is incrementing.