- Home /
Altering Material Alpha While Raycast is NOT Hitting
Hi, I have a top down shooter I am making, I have a script that makes it to when you go under a piece of geometry, the alpha value of that object goes down, only thing is that once I leave from under the object, the alpha value doesnt return to normal.
Here is my code so far...
var target : Transform;
function Update ()
{
var hit : RaycastHit;
Debug.DrawLine(transform.position, target.position, Color.green);
if(Physics.Linecast(target.position, transform.position, hit))
{
hit.transform.renderer.material.color.a = 0.3f;
Debug.Log("Something in the way");
}
if (!Physics.Linecast(target.position, transform.position, hit))
{
hit.transform.renderer.material.color.a = 1.0f;
Debug.Log("Nothing In the Way!");
}
}
I tried to think about it before I posted a question, and one of my ideas was to store the object hit into a variable, that way when the raycast leaves, I could just change
"hit.transform.renderer.material.color.a = 1.0f;"
to
VariableHoldingObject.transform.renderer.material.color.a = 1.0f;
Any help or suggestions would be greatly appreciated, let me know if you need further info!
Comment