The above says it all. I am looking to have a GUI above a enemy object, so that my character camera can see enemies from far away. I am relatively new to working with the GUI functions so could someone please point me in the right direction. Thanks
Putting something from the GUI class such as using GUI.DrawTexture() above a world object is a bit complicated…partly because you have to make two coordinate changes, and partly because GUI.* stuff is anchored in the upper left corner. Let me suggest instead that you use either a GUITexture or a GUIText object. Both are created from the ‘GameObject > Create Other’ menu. GUITextures and GUIText object live in Viewport space. So we can use a script like this to track and object:
#pragma strict
var target : Transform;
var offset = Vector3(0.0, 0.75, 0.0);
function Update() {
var pos = target.position + offset;
transform.position = Camera.main.WorldToViewportPoint(pos);
}
You attach this script to a GUITexture. Then drag and drop the game object you want to follow on the ‘target’ variable.
Note when making the GUITexture, you may want to edit the Pixel Offset to set the ‘Y’ value to 0.0. This will anchor the GUITexture by the bottom.