- Home /
Removing A Component From An Instantiated Prefab After X More Are Instantiated
I want to remove a rigidbody from one instantiated prefab after a specific number more are instantiated.I know you can do Destroy (blank.rigidbody) but I want it to do that after a certain number more prefabs are instantiated. Any help would be appreciated.
Answer by Kourosh · Apr 21, 2011 at 03:27 AM
Attach this script your prefabs:
static var counter:int; // "static" will define a global variable.
function Start(){ counter++; // On object instantiated add one more the counter
if(counter >= 10){ // if counter reached 10 and above remove the rigidbody. Destroy(GetComponent(Rigidbody)); } }
I want it to destroy the instantiated objects rigid body after x more are spawned. This is destroying all of the instantiated objects rigid body after x are spawned. I want to remove the rigidybody from an instantiated object after x more of them are spawned and only from the object which four more had spawned after.