Hi! I was wondering how to make a crosshair turn red when it’s over an enemy? What I was thinking was, raycasting perhaps? So it draws an imaginary line then when it’s in line with a gameobject tagged enemy it will switch the crosshair 2d Texture with a red one that I’ll make. (no need to change the color within unity)
This is my crosshair script:
var crosshairTexture : Texture2D;
var position : Rect;
static var OriginalOn = true;
function Start()
{
position = Rect((Screen.width - crosshairTexture.width) / 2, (Screen.height - crosshairTexture.height) /2, crosshairTexture.width, crosshairTexture.height);
}
function OnGUI()
{
if(OriginalOn == true)
{
GUI.DrawTexture(position, crosshairTexture);
}
}
use a simple raycast to check if you’ve got your crosshair hovering over an enemy, if that is the case, switch the textures for the crosshair.
or was the question about how you made a raycast and used it to switch the textures?, also, please reread your posts after you’ve posted them to make sure your code was formatted correctly
If you cast that in update you get a response for every frame, the return value of the raycasthit is the gameobject itself, with all attached scripts, rigidbodies, values etc etc. SO, what you do is that you write something along the lines of