- Home /
OnTriggerEnter change GuiText problem
Hi there, I have made the following script but something wrong with the code
function OnTriggerEnter (myTrigger : Collider)
{
...
guiText.text="Hello";
}
I have linked this script into a Guitext Then when the fuction runs i am getting the following error:
MissingComponentException: There is no 'GUIText' attached to the "Sphere_U" game object, but a script is trying to access it.
You probably need to add a GUIText to the game object "Sphere_U". Or your script needs to check if the component is attached before using it.
Scorescript+$OnTriggerEnter$22+$.MoveNext () (at Assets/Scripts/Scorescript.js:28)
What's my error? The Spere_U is the object that my player touch and the function activated Thx in advance!!
Answer by Berenger · May 11, 2012 at 04:12 PM
The output says it all. A GUIText is a component you can add from the toolbar Components->Rendering->GUI Text. If the GameObject your script is attached to doesn't have that component doesn't have a GUIText, guiText (which is a shortcut for GetComponent.()) will return null.
I don't understand clearly your answer but i solve my problem with the following: I make a new js file with the followings: function OnGUI(){ guiText.text = Scorescript.gather; }
gather is a variable which changes onTriggerEnter fun into ScoreScript js file...
Thx for the answer anyway