How to make crosshair turn red when it targets a enemy?

Im having problems in making the Crosshair turn red when it on a enemy? Can anybody give me some tips or a script I can use

var crosshair01 : GUITexture;
    var FpsPlayer;
     
    function Start() {  
         FpsPlayer = GameObject.FindWithTag("Player");
    }
     
    function OnMouseOver () {  
        var targetDistance = Vector3.Distance(FpsPlayer.transform.position, transform.position);
            if(targetDistance < 12.0){
            crosshair01.guiTexture.color = Color(1,0,0,0.5);
        }
    }
     
    function OnMouseExit () {
            crosshair01.guiTexture.color = Color(1,1,1,0.5);
    }

use raycast to detect the presence of the opponent.
if the raycast hit the opponent, just switch the crosshair color.

Thanks
Now Im using a new script. I have the crosshair working but it still wont change colors.

var crosshair: Texture2D; // drag the normal crosshair here
var redCrosshair: Texture2D; // drag the red crosshair here
var position :Rect;
var hit: RaycastHit;

private var isEnemy: boolean = false;

function Update(){
    if (Physics.Raycast(transform.position, transform.forward, hit, 100))
    {
        isEnemy = (hit.transform.tag == "Enemy"); // assign the comparison result to is enemy
       
    }
}

function OnGUI(){
    var cross = crosshair; // assume normal crosshair
    if (isEnemy) cross = redCrosshair; // change to red if isEnemy is true
    GUI.DrawTexture(position, cross);
}

is the bool isEnemy definatly change to true when you think it is?
add a GUI.Label(someRect, "Pointing at enemy: " + isEnemy) so you can see is say true or fal

Try adding this to the onGUI function, after the if statement:

renderer.material.color = color.red;

If that doesn’t work try adding it under the update function in the if statement.
Hope this helps!

The most simple to do is using GUITexture. use 2 cross textures blue and red for example, the blue is set active and the red is set inactive by default.
Code:

#pragma strict

var standardCross : GameObject;
var redCross : GameObject;


var hit: RaycastHit; 


function Start ()
{
    standardCross.gameObject.SetActive(true);
}


function Update(){


    if (Physics.Raycast(transform.position, transform.forward, hit, 100))
    {
       if (hit.transform.tag == "Enemy")
       {
            redCross.gameObject.SetActive(true);
            standardCross.gameObject.SetActive(false);
       }       
    }
    else
       {
               redCross.gameObject.SetActive(false);
                standardCross.gameObject.SetActive(true);
       }
}