How do I use a trigger to change the GUIText

Hi all, Im pretty new to Unity and Java scripting but I was making good progress until I hit this problem. Here is my code:

function OnTriggerEnter (myTrigger : Collider) 
{
    if(myTrigger.gameObject.name == "box")
    {
        Debug.Log("Box went through!");
        var targetText = GameObject.FindWithTag("Score");
        targetText.guiText.text = name;
    }
}

My Debug text works, but I know I am doing something stupid with the GUI part. Can anyone help me out and point me in the right direction?

Cheers!

Make sure your GameObject.FindWithTag(“Score”); finds the GUItext, otherwise it will return null and won’t set anything. you can check it with if(varText == null)

Alternatively, you can set your var to be a GUIText so that you can set it with targetText.text = name;

In the least, you can make it public and attach the GUIText object from hierarchy window to your script. But in order to do that, you should make your variable public.

GUIText is a component attached to game object so once you have the object you still to fetch the component with GetComponent();