- Home /
The question is answered, right answer was accepted
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?
Answer by aldonaletto · Nov 26, 2013 at 12:05 AM
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);
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Difference between capitalized component in AddComponent and Destroy 2 Answers
"Some objects were not cleaned up when closing the scene" 1 Answer
Why doesn't this script work?? Please help.. 1 Answer
C# destroy gameobject with tag 5 Answers