Alright so I have this setup. I have a canon object which has a script on it that instantiates a canonball rigidbody and adds force to it which sends it flying forward. The canonball has a sphere collider and it is not a trigger. That part works great, I wanted to make another script which I would use to attach to an object I want to destroy when it gets hit by the canonball, but before it gets destroyed, it instantiates another object that represents broken parts of the object that gets destroyed. Here is the script I’m using:
using UnityEngine;
using System.Collections;
public class DestroyDoor : MonoBehaviour
{
public Transform brokenPos;
public GameObject brokenDoor;
// Use this for initialization
void OnCollisionEnter(Collider other)
{
if (gameObject.tag == "Canonball")
Instantiate(brokenDoor, brokenPos.position, brokenPos.rotation);
Destroy(gameObject);
}
}
It absolutely does not work lol doesn’t instantiate anything nor it does destroy anything, it did destroy the object but I saved the script or did something and now it doesn’t even do that. So could somebody please help me out because I’m not sure how to go about a rigidbody hitting something and using that as a OnTriggerEnter or OnCollisionEnter, whatever. Could somebody please write a working script and explain please? Thanks!