How can I destroy a GameObject from a Rigidbody variable?

I’m trying to make an enemy fire a thing while it runs at you. It’s working pretty well, except when I try to remove the bullet after a while, it only removes the object’s rigidbody. Here’s the script I have right now:

var spit:Rigidbody;

function Spit()
{
	var SpitClone = Instantiate(spit, transform.position, transform.rotation);
	SpitClone.velocity = transform.TransformDirection(Vector3.forward * 10);
	Physics.IgnoreCollision(SpitClone.collider, collider);
	Destroy(SpitClone, 10);
}

How can I destroy the whole GameObject?

1 Answer

1

Instantiate returns a reference to the same kind of component passed - a Rigidbody in this case. Just use it to access the GameObject:

Destroy(SpitClone.gameObject, 10);