- Home /
Bullet hole fade out and tagging
Hi guys, I've already got it figured out how I'm going to put a bullet hole where the raycast hits but I have two questions:
One, I want to make it fade out. But not the alpha channel for the material but actually destroy it, just not abruptly. What line of code would I use for that?
Also, I know there's a certain line of code that says if the raycast hits this item with a certain tag an event happens. In this case the bullet hole. So what is the proper syntax for that? Thank very much for the help.
Answer by Bicko · Mar 02, 2012 at 03:05 PM
As far as fading out, you'll probably want to adjust the alpha value of the material, and test to see if it's reached 0. Once it has, you can destroy it. Something like this maybe (untested).
void FixedUpdate()
{
renderer.material.color = Color.Lerp(renderer.material.color, new Color(1,1,1,0), Time.deltaTime);
if(renderer.material.color.a <= 0)
Destroy();
}
For the Raycasts, that's pretty simple. Do your raycast, and then test if what was hit has the tag you're looking for. Quick (again untested) example:
RaycastHit hit;
if(Physics.Raycast(transform.position, Vector3.forward, out hit))
if(hit.collider.tag == "MyTag")
print("Hit the desired object");