startTimer working for first on screen message but not the 2nd on screen message

Hi,

I am a new user of Unity and have a basic question … I think.

I have a game where you collect coins, you cannot open a door unless you have more than 10. If you do not a message pops up saying you need 10 or more. This message has a timer attached to it so that it disappears after a few seconds. If you do have more than 10 coins the door gets destroyed and a message pops up saying well done, I also attached the timer to this one yet the message stays on screen. Any advice on getting the timer to work on that too? Will put code below this, hopefully formatting is ok.
Thanks!

var timer:float;
var startTimer:System.Boolean;

function Update ()

{

	if (startTimer == true)
	{
		timer = timer + 1;
		if (timer >= 200)
		{
			startTimer = false;
			timer = 0;
			GameObject.Find("messageUI").GetComponent.<UI.Text>().text="";
		}
	}

}


function OnTriggerEnter (other : Collider)

{	

	if((other.tag == "Torch")&& (ScoreCount.gscore>=10))
	{
		Destroy(gameObject);
		startTimer = true;
		GameObject.Find("messageUI").GetComponent.<UI.Text>().text="Well done, you unlocked the door!";
		
	}

	else if ((other.tag == "Torch")&& (ScoreCount.gscore<10))
	{
		GameObject.Find("messageUI").GetComponent.<UI.Text>().text="10 coins needed to unlock this door. You need another " + (10-ScoreCount.gscore) + " coins!";
		startTimer = true;

	}

}

The problem is you destroy the game object. When it’s destroyed, it’s update function will no longer fire, so the code that hides the timer is never activated.

There are various way to solve this, but a straightforward solution would be to move the auto-hide intelligence to the message UI. Auto-hiding text is typically a characteristic of the text component, not something any other GameObject should have to worry about.

Simply remove all the timer logic form this script, and add the following script to the MessageUI object (I’ve used C#, feel free to translate to your favorite scripting language):

using UnityEngine;
using UnityEngine.UI;

public class AutoHide : MonoBehaviour
{
    private float _timer;

    public void Update()
    {
        var text = GetComponent<Text>().text;
        if (text == "") return;

        _timer = _timer + 1;
        if (_timer >= 200)
        {
            _timer = 0;
            GetComponent<Text>().text = "";
        }
    }
}