- Home /
Question by
allfader · Feb 16, 2013 at 05:46 PM ·
javascriptguitexturetargeting
GuiTexture on enemy when in range and in line of sight.
I`m working on a targeting script which marks a target with a guitexture when it`s in range and in line of sight, and it works great, but I need it to disappear when it`s no longer in sight or range. Any ideas on how I can do this?
function attack ()
{if (!CanSeeTarget ())
return;
myGui = closest.GetComponentInChildren(GUITexture);
myGui.color.a = 1;
yield;
}
}
function CanSeeTarget () : boolean
{
if (Vector3.Distance(transform.position, closest.position) > attackRange)
//lock
return false;
var hit : RaycastHit;
if (Physics.Linecast (transform.position, closest.position, hit))
return hit.transform == closest;
return false;
}
Comment
Your answer
Follow this Question
Related Questions
Door Problem 1 Answer
Make crosshairs disappear while aiming 0 Answers
Health Script not working 1 Answer
How to Make A GUI Keypad Login With Texture Buttons 1 Answer
random target selection 2 Answers