- Home /
Destroyed clones freezing but not disappearing?
Hi All, I'm trying to destroy a projectile after a specific period of time, to increase perfomance (on mobile). The projectile is instantiated from a prefab and the script is on a dummy object usd as an emitter. I have a number of collisions working fine and the instantiation.
The problem I'm having is that the cloned object freezes, but does not disappear from display. What do I need to do to make the cloned object destroy and remove itself from the scene?
This is the script (JS) attached:
var projectile : Rigidbody;
var projectileSpeed :int = 100;
function Update(){
if (FireButton.fired==true){
var projectileClone : Rigidbody;
projectileClone = Instantiate(projectile, transform.position, transform.rotation);
projectileClone.velocity = transform.TransformDirection (Vector3.forward * projectileSpeed);
FireButton.fired=false;
Destroy(projectileClone,1);//this is supposed to destroy the clone after 1 second
}
}
Any advice would be appreciated.
Best Regards Chris
Answer by Talimar · Aug 31, 2011 at 06:06 AM
You're only destroying the rigidbody. You need to destroy the GameObject. Make your projectileClone of type GameObject instead, or Destroy(projectileClone.gameObject).
Thanks Blitzwing, can I convert it in the script after the instnatiation, as the velocity wont work on object type of GameObject? Cheers Chris
Just use the second part of what I said, Destroy(projectileClone.gameObject). If you wanted to edit the velocity of a GameObject, you just do myGameObject.rigidbody.velocity = whatever.
Your answer
Follow this Question
Related Questions
UI Object is there but can't destroy it. 0 Answers
Destroy an instance of a prefab 1 Answer
restricting clone number 2 Answers
JS file deleting multiple game objects 0 Answers
Destroy Objects after a set time 2 Answers