- Home /
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.
Answer by Aydan · Apr 22, 2011 at 03:19 AM
I think this should work
if (counter == count + 4){
Destroy (GetComponent (Rigidbody));
}
Your answer
Follow this Question
Related Questions
Unity Frame Drop From Instantiating Prefab that has script 0 Answers
Set a Prefab's variable when you instantiate it, but before it calls Awake? 2 Answers
Checking Collision on instantiated object 0 Answers
Rigidbodies violently repel when replacing with pre-shattered opject 2 Answers
How to make sprites instantiate based on randomly generated integer? 1 Answer