You know games like Mass Effect where when you see an enemy, then a red triangle would appear on your HUD so it makes it obvious it’s a threat. I’m curious how that can be done whenever I step in a sphere trigger and an Item in view makes a texture outline it. I’m mainly looking for theories and suggestions for this one ![]()
Thanks
Probably lots of ideas (all correct).
My first approach would be to just do a check for other intractable objects within a certain distance in front of the player’s camera. If you find one, you have your HUD targeting texture draw on the screen using your WorldToScreenPoint type function, add some nifty rotating and animated textures for fun.
Thanks a lot for the tip I’ll look into it ![]()
I did some looking made a simple example and ran into a roadblock this is what I have so far:
var target : Transform;
var targetTex : Texture2D;
var screenPosX : float;
var screenPosY : float;
function Update () {
var screenPos = camera.WorldToScreenPoint(target.position);
screenPosX = screenPos.x;
screenPosy = screenPos.y;
print("target is " + screenPos.x + " pixels from the left " + screenPos.y + " pixels from the top"); // I used this to confirm screenPos.y works, which it does...
}
function OnGUI(){
GUI.DrawTexture(Rect(screenPosX - 25, screenPosY, 50, 50),targetTex);
}
Most everything works no errors. But my texture is not aligning with my game object on the Y axis and the way I look at it, it should work but It only stays in the X axis.
Edit: Sorry
figured out my problom misspelled screenPosY
.
Thanks, works great!
The documentation needs a warning sign on this: invert the Y axis. The Screen and Camera use opposite Y values (ie, one uses (0,0) as the top left the other uses (0,0) as the bottom left).
So before your OnGUI:
screenPos.y = Screen.height - screenPos.y
Edit: and correct spelling helps, too ![]()
Lol thanks Timmer, I’ll keep that in mind. I also found a weird bug with the WorldToScreenPoint function, It seems to shows it as if a line going through your camera. for example you’ll see the texture behind you when the object is actually right in front of you. Do you know how I can fix that issue?
Hello ![]()
do you have a screenshot I can check? ![]()
If your script detects when the threat object comes within range of the player, then it also has to detect whether the player is looking at the object. Otherwise, an object behind the player will be detected and marked on the screen - since you are only using the X and Y coordinates, you can still show a marker texture for objects that the player can’t see.
An easy way to check if the object is in front of the camera is to look at the Z coordinate of the point returned by Camera.WorldToScreenPoint - it will be negative if the object is behind.
Alright, Thanks for the info I’ll look into it.

