hey, so when i try and use the code below to destroy my cloned bullet it doesnt destroy, it doesnt even fire the onCollisionEnter event so i am very confused. the bullet has a collider and a rigidbody so i am very confused. any help is appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shootScript : MonoBehaviour
{
public Rigidbody projectile;
public Transform barrelEnd;
// shoot the gun *bang*
void Update()
{
if (Input.GetMouseButtonDown(0)) {
projectile = Instantiate(projectile, barrelEnd.position, barrelEnd.rotation);
projectile.velocity = transform.TransformDirection(-30, 0, 0);
Destroy(projectile.gameObject, 10);
}
}
// destroy the bullet on enemy impact
private void OnCollisionEnter(Collision collision)
{
Debug.Log("test");
if (collision.gameObject.tag == "enemy") {
Destroy(gameObject);
}
}
}
↧