I have a manager script which calculates time remaning and OnGUI() function shows the time on screen....but after it reaches certain time i have to turn off gui....How can i do so...Please Help

Manager Script

using UnityEngine;
using System.Collections;

public class Timer : MonoBehaviour {

private GameObject[] detect;
private int i;

public float startTime;
private string currentTime;

public GUISkin skin;
public Rect timerRect;


// Use this for initialization
void Start() 
{
    startTime = 3.0f;
    detect = GameObject.FindGameObjectsWithTag("Enemy");
}
	
// Update is called once per frame
void Update() 
{
    for (i = 0; i < detect.Length; i++)
    {
        if (detect*.GetComponent<Detection>().IsDetected == true)*

{
if (startTime >= 0)
{
startTime -= Time.deltaTime;
currentTime = string.Format(“{0:0.0}”, startTime);
//Debug.Log(currentTime);
}
}
}

  • }*
    void OnGUI()
    {
    GUI.skin = skin;
    GUI.Label(timerRect, currentTime, skin.GetStyle(“Timer”));
    }
    }

Change your OnGUI() to this.

void OnGUI()
 {
     if(startTime < 0)
         return;
     GUI.skin = skin;
     GUI.Label(timerRect, currentTime, skin.GetStyle("Timer"));
 }