- Home /
changing guiTexture color with raycast
Hi, I'm trying to make a script witch allows a raycast to change the color of the guiTexture that I will be using as a cursor. The point is that the cursor turns red when your looking at an enemy. This is my first time using raycasts and I have checked trough a lot of tutorials and i have almost got it now. I'm using the debug.DrawRay to see if the ray is following the camera, and it is. but for some reason the cursor is always red. Thank you in advance!!
PS: I do have a box tagged as Enemy and I have selected the GameObject for the Cursor variable correctly.
Here's the script
var Cursor : GameObject;
function Update () {
var hit : RaycastHit;
Debug.DrawRay(transform.position, transform.forward);
if (Physics.Raycast(transform.position, transform.forward, hit))
{
if (hit.collider.tag == "Enemy"){
Cursor.guiTexture.color = Color.red;
}
}
}
Answer by robertbu · Mar 23, 2014 at 06:49 PM
Once you set the color to red, you have nothing to reset it. Insert on at line 5:
Cursor.guiTexture.color = Color.white;
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
C# Check Physics.Raycast Once 0 Answers
Physics.Raycast AI problem 1 Answer