How do I create a variable from a... GUIlabel?

This seems like a stupid question, but i’ve got a script that counts upwards from 0.0 indefinitely until the player reaches the end of the level, and I want to set the end number as a variable to be added with the numbers of all the other levels once the player has completed all those levels. Is there a simple way to do that?

Here is the script:

var MyFont : Font; 
static var Timer : float = 0.0; 
static var maybe : boolean = false; 
static var gui : boolean = false; 

function Update() { 
	if(maybe == true)
		Timer += Time.deltaTime;
	}
		
	
function OnGUI() { 
	if(gui == true) 
		{
		GUI.skin.font = MyFont;
		GUI.color = Color.blue; 
		GUI.Label(Rect(235, 420, 200, 100), "Final Time: " + Timer.ToString("0.00"));
	}
	else 
	{ 
		GUI.skin.font = MyFont;
		GUI.color = Color.blue; 
		GUI.Label(Rect(292, 420, 100, 100), "" + Timer.ToString("0.00"));
		}
	}

I need the “Timer” variable to be another variable once it is set to whatever time the player took to complete the level. Any help would be appreciated.

For creating timers, Coroutines are the best method.

Call the timer using

StartCoroutine ("MyTimer");

Use the following code for timer :slight_smile:

public GUIText myText;

	IEnumerator MyTimer()
	{
		//timer maximum, here's a timer counts down 30 sec
		int x = 30;

		for(;;)
		{
			myText.text = x.ToString();

			//waiting for 1 second
			yield return new WaitForSeconds(1f);

			x-=1;
			if(x==0)
			{
				//To do when the timer finishes couting

				//Reset x=30 if you want to loop the timer
			}
		}
	}