gameTimer needs to be based on an event, not onGUI

Hi - I have a timer function set up which I programmed based on some posting here, but it is set up to run through the onGUI event, so the time is based on the amount of time the game has been running (I guess). But what I want it to do is not start the timer til the user clicks the logo to begin play. The way I have it set up now, if the user takes 10 seconds to click the start button, and the game timer is set to count down from 60 seconds, by the time they begin play there will only be 50 seconds left in the game. How do I change this to trigger after the click?

Here’s my code:


private var startTime = 60;
var textTime : String; //added this member variable here so we can access it through other scripts
var beginPlay : boolean = false;
var guiTime : int;

function OnGUI () {
	if (beginPlay == true){
		guiTime = startTime - Time.time; //how to count down
		var timeText = guiTime.ToString();
		if (guiTime < 0){
		} else {
			timerTextRef.text = timeText;
			textTime = timeText;


var cameraRef : GameObject;

function Update () {
  	if (Input.touchCount > 0 ) {
    	for(var i : int = 0; i< Input.touchCount;i++) {
      		var touch : Touch = Input.GetTouch(i);
      		if  ( touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position)) {
        		guiTexture.enabled = false;
				cameraRef.GetComponent(Timer).beginPlay = true;

I ended up doing this. I’m sure someone will inform me that this is the wrong way to do timers, but it worked for my purposes:

function Start(){
	startTime = 10;

function timeDown(){
	yield WaitForSeconds (1);

function repeatTime(){
	if (startTime < 1){
	} else {

You need to set startTime when the touch is detected, not on start (by assigning it statically), so put startTime = 60 after, say , guiTexture.enabled = false;