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
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.
– Talimar