- Home /
Destroying projectile on collision with every object.
How would I destroy a projectile on collision with any object.
This is the code I have at the moment.
private void LaunchProjectile()
{
// Creates the projectile
var bullet = (GameObject)Instantiate(
projectile,
firePoint.position,
firePoint.rotation);
// Add velocity to the projectile
bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * 10;
// Destroy the projectile after 5 seconds
Destroy(bullet, 5.0f);
}
Comment
Answer by omerselman · Oct 07, 2017 at 11:12 AM
I hate people giving referance to documents but im this case the referancing to a document works fine. In the documentation you will see what you need in another example section https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html