Hello, I recently made a script to destroy objects when the collide with bullets but the object does not destroy and instead bounces off the object. I do not know what the exact problem is because I have the bullet prefab and explosion prefab made already. Can someone please help me know why objects are not being destroyed after they are hit by a bullet?
Here is my code for the bullet:
var speed : float = 30;
var explosion : GameObject;
function Start () {
Invoke("Destroy_Bullet", 1.0);
}
function Update () {
transform.Translate (Vector3.forward * speed * Time.deltaTime);
}
function OnTriggerEnter (other : Collider) {
if (other.gameObject.tag == "shooter") {
Instantiate (explosion, transform.position, transform.rotation);
Destroy(gameObject);
}
}
function Destroy_Bullet () {
Destroy(gameObject);
}
Code for the enemy:
function OnTriggerEnter(other: Collider){
Destroy(other.gameObject);
}