- Home /
Pointers to Show Off-Screen Enemies
I have made this script to create a GUI Texture at every Enemy (/every tag you tell it to) and it works great so far but now I want to add an off screen indicator to show where enemies you can't see are. (sort of like this)
P.S- I dont need a real script... just "pointers" on how to do it
-heres my code-
var multiplier : float;
var style : GUIStyle;
private var list : String;
var range : int;
var TargetTags : String[];
var TargetTexture : Texture[];
function OnGUI ()
{
for(var t = 0; t < TargetTags.Length; t ++)
{
var pointers : GameObject[];
pointers = GameObject.FindGameObjectsWithTag(TargetTags[t]);
list += "------------------ \n" + TargetTags[t] + "\n ------------------ \n";
for(var pointer in pointers)
{
var dist = Vector3.Distance(transform.position,pointer.transform.position);
if(dist < range)
{
if(pointer.renderer.isVisible)
{
var size = multiplier / dist;
var rect : Vector3 = camera.WorldToScreenPoint(pointer.transform.position);
GUI.DrawTexture(Rect(rect.x -size/2,Screen.height - rect.y - size/2,size,size),TargetTexture[t],ScaleMode.StretchToFill,true,10.0f);
}
list += pointer.name + "\n";
}
}
}
GUILayout.Box(list);
list = "";
}
Answer by trvr · Jun 21, 2013 at 04:31 PM
Try using something like this:
var allEnemies = GameObject.FindGameObjectsWithTag("Enemy");
to find all game objects with a certain tag, then use:
transform.LookAt
to get the arrows to automagically face the right way. As for only showing objects off camera, have a look at Renderer.OnBecameInvisible. Looks like that will do exactly what you need.
Sorry...It seems I wasn't very clear before. I want a GUI Texture to point to the offscreen objects not have myself turn to face the object. The allEnemies and OnBecameInvisible seem okay for what I want but I need something to find which direction the object is in- maybe using Vector3.Dot?
Your answer
Follow this Question
Related Questions
how can i get GUI.Button presse(or down not click) 3 Answers
Where do I assign GUI scripts? 1 Answer
Intro GUI Text Script... 3 Answers
GUI Resolution Ajust 1 Answer
Load an image from www and save it for offline use 0 Answers