Hi everybody,
I have a 3D game. In the Hierarchy there is a GameObject that has a component “GUIText”. GUIText is visible by the camera and has some “Example Text”. I need to change the Gui Text via Healscript when enemy is destroyed. In the HealthScript I have this condition which defines destroying the Enemy:

if (hp <= 0)
{
	Destroy(gameObject);
}

Can somebody help me, please? I created a public variable but I am not able to assign the Gui Text because it is in that GameObject. I probably need to use GameObject.Find but can not figure it out.
Thanks.

So, get a reference to the GameObject(either by name or by assigning it through the inspector).

// c#
GUIText guitext = GameObject.Find("theGameObjectNameThatHasTheGUITextObjectOnItAsAChild").GetComponent<GUIText>();

// javascript
var guitext:GUIText = GameObject.Find("theGameObjectNameThatHasTheGUITextObjectOnItAsAChild").GetComponent.<GUIText>();

if (hp <= 0)
{
Destroy(gameObject);
GameObject.Find(“NameOfGuiText”).GetComponent().text = “New text”;
}

When you say there is a GUIText component attached to the game object in the hierarchy panel, you have to use this below code for accessing the text.

Suppose you want the text changed when the enemy dies:

private void Update()
{
   if (enemyHealth <= 0)
   {
       guiText.text = "Some Text Here";
   }

}

and attached the script to the game object where there is a GUIText component.