Search code examples
c#unity-game-engineunity-ui

How can i activate a method by button and call it in update method if it true?


I know the question is a bit long and has multiple issues but could not get done with it. I have a button on settings menu and when clicked on it, it should activate a method in script and i need to call that method in Update() method if it is active.

So i have a "Main" gameobject that need to manage this event and "Test" script on it. The "TebsSkipButton" button is on the "Settings" gameobject and the button should activate the "TEBS" method which is in the "Test" script.

And then i need to check "TEBS" method if it is active or not in Update() method of the "Test" script. If it is true, the method should run.

I didn't created the script yet to attach to the button and to activate the method of the "Test" script.

Here what i tried to write something on "Test" script;

using UnityEngine.UI;
using Ink.Runtime;

   void Update()
    {

    }

    public void TEBS(bool isActive)    {
           int tebs = (int)_inkStory.variablesState["TEBS"];

            if (tebs > 0)
            {
                _skipButton.SetActive(true);
            }
            else
            {
                _skipButton.SetActive(false);
            } 
    }

I am also using Ink plugin to run the story but it is not related with the issue.

Thanks in advance.


Solution

  • Make a bool variable, and once you click on the button, it will call the function which set this bool variable to True,

    then make the check on Update function with this bool variable to run your desired Function .