guitext and texture following gameobject, how to destroy and alternatives?

Okay, i’m trying to create gui system for objects in my scene that follow them around (health shield name background for bars and so on), right now my biggest worries are that hierarchy is getting flooded by guitext and guitexture object clones as i need to instantiate each one for every object so here is my question:

  1. is there any better way to achieve this?
  2. if not, how can i destroy those clones when the object that created them is destroyed?

i followed this tutorial on youtube and expanded on that.

thanks.

edit: oh yeah i use c# in this.

For the hierarchy problem, use:

myhb.transform.parent = this.gameObject.transform;

and it should parent the HPbar to the object calling it in hierarchy.

as for the second problem, you need to check if the target is in front or back.

Camera.main.WorldToViewportPoint(transform.position);

that piece of code gives you XYZ values from wich you can see if the target is in front of you or not, and destroy the bars or set size to 0 or something like that…

this is how im using it is somewhere along like this:

bool visible = false;

abCookie = Camera.main.WorldToViewportPoint(transform.position);
		//abCookie.x  checks if it is in view vertically
		//abCookie .y checks if it is in view horizontally
		//abCookie .z checks if we are front or behind the target
		//abCookie .z < maxDist just checks if its otherwise in view but if its too far it doesn't create bars


if (abCookie.x > 0 && abCookie.x < 1 && abCookie.y > 0 && abCookie.y < 1 && abCookie.z > 0 && abCookie.z < maxDist)
		{
			if (!visible)
			{
				CreateBars();
			}
			visible = true;
		}
		else
		{
			if (visible)
			{
				RemoveBars();
			}
			visible = false;
		}

hope it helps.