x


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.

more ▼

asked Apr 21 '11 at 03:19 AM

anonymous 2 gravatar image

anonymous 2
14 4 4 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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));
  }
}
more ▼

answered Apr 21 '11 at 03:27 AM

Kourosh gravatar image

Kourosh
1.5k 48 53 65

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.

Apr 21 '11 at 02:34 PM anonymous 2
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1948
x1862
x1725
x1286
x785

asked: Apr 21 '11 at 03:19 AM

Seen: 1068 times

Last Updated: Apr 21 '11 at 03:19 AM