x


Removing A Component From An Instantiated Prefab After X More Are Instantiated

I am trying to remove a rigidbody from an instantiated object after x more are instantiated after it.Here is my script :

public var cube : Transform;
public var cubeclone : Transform;

public var counter;




 function Update () { 

    if (Input.GetButtonDown("Fire1")){
        var count = counter;




     cubeclone = Instantiate (cube, Vector3 (transform.position.x, transform.position.y, 0), Quaternion.identity);

        transform.position.y += 0.5;
        counter++;

     if (counter == count + 4) {
       Destroy(cubeclone.rigidbody);}

                        }

        }

Also the script only instantiates a cube if counter++ is at the bottom like it is now. Any help would be appreciated.

more ▼

asked Apr 22 '11 at 01:31 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

I think this should work

if (counter == count + 4){
    Destroy (GetComponent (Rigidbody));
}
more ▼

answered Apr 22 '11 at 03:19 AM

Aydan gravatar image

Aydan
180 28 37 47

Nope. Already tried that. Doesn't work.

Apr 22 '11 at 04:34 AM 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:

x3442
x1781
x1667
x1249
x302

asked: Apr 22 '11 at 01:31 AM

Seen: 1188 times

Last Updated: Apr 22 '11 at 01:38 AM