SO I’ve got a game where you shoot bullets at other players in slow motion. You can deflect bullets with other bullets much like in the movie “Wanted”. To help communicate to the player where the bullets are I put some trails on them. However, if I destroy the game object the trails disappear.
I created this script that checks the collision with the wall, instantiates a bullet hole on the wall, and then turns off the mesh renderer & mesh collider. However when I shoot a wall the collider does not shut off until after it has collided so I end up with invisible trails bouncing to the ground.
Any Suggestions?
Here’s the code
void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.name == "Wall")
{
// Make sure the shot has made contact
Debug.LogWarning("Collided with wall");
// Find the contact point so we can instantiate the Bullet hole facing the player
ContactPoint contact = collision.contacts[0];
Quaternion rot = Quaternion.FromToRotation(Vector3.down, contact.normal);
Vector3 pos = contact.point;
// Create the Bullet hole facing the player
Instantiate(bulletHole, pos, rot);
// Destroy the bullet WITHOUT turning off the trail renderer
renderer.enabled = false;
collider.enabled = false;
Destroy(gameObject, 5);
}
}