DestroyObject is not destroying everything.

So I have my main object which I want to shoot and kill. My detection is working great and all but when I spawn the dead/broken version of that object the original object remains (dead object does spawn correctly) but from what I can tell is it’s script simply got destroyed.

function buildDeath() {
 var tst = Instantiate(deadMe,transform.position,new Quaternion());
 DestroyObject(this);
}

Now I’m assuming that “this” on my destroy object is referring to the gameobject running the script and not the script itself. If I’m wrong then how do I target the gameobject.

Thanks,

Ron

Use Destroy(gameObject) to destroy the GameObject to which the script is attached, along with all attached components.

Note that gameObject is equivalent to this.gameObject, and your current method (destroying this) is in fact destroying the component itself.

Also note, from the docs:

Destroy is inherited from the UnityEngine.Object base class. Javascript users should consider making a call to UnityEngine.Object.Destroy, rather than Object.Destroy to avoid references being resolved to the .Net System.Object class.