Unity Timer start by button instead of update/on-open.

Hello,

I have a script wich includes a timer, only problem is that it starts as soon as you start the app.
So what i would like to have is to start the script by button.
Can someone help me to accomplish that?

At this point this is how it starts and stops :

void Update () {

	float time = introTimer - Time.timeSinceLevelLoad;
	textTimer.text = time.ToString ("0") + "..";

	if (time <= 0) {
		TimeUp ();
	}
}

Some solutions:

  • Have the component start disabled, then enable it when you click the button. Update() isn’t called on a disabled MonoBehaviour. Unity - Scripting API: Behaviour.enabled

  • Make a public bool called isActive and set it to false by default. Now wrap all the code in Update() in an if statement checking to see if isActive is true. Have the button set isActive to true.