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
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);
}
}