- Home /
Delete Component at Runtime
My player needs to have a hingeJoint attached only when he is colliding with a rope. When the player presses "a" for example, we would let go, releasing the rope and falling to the ground. Unfortunately, what I've found to happen was that just making the value connectedBody
null doesn't work because the player then hangs where he is in midspace. So the only way I know of to do it is to add/delete the hingeJoint component at runtime. I've added the hingeJoint using:
transform.gameObject.AddComponent("hingeJoint");
But I can't find a way to delete the hingeJoint. Any help would be appreciated.
Yes, but, how can I find the hinge joint component via script.
I have the gameObject with findGameObject()
any hints?
I tried this:
quadro_bicileta = GameObject.Find ("quadro_bike_3D"); hinge = quadro_bicileta.gameObject.GetComponent();
Destroy(quadro_bicileta.gameObject.GetComponent());
Destroy(hinge);
--- but it does not work ---
I appretiate any hints, help and code
Answer by whydoidoit · Jun 22, 2012 at 07:30 PM
You want to do
Component.Destroy(yourComponent);
It can be just this in a mono behaviour:
Destroy(yourComponent);
Your answer
Follow this Question
Related Questions
Export objects to a .3DS file at runtime 1 Answer
Deleting a rigidbody 1 Answer
2D Animation does not start 1 Answer
Sloppy HingeJoints 0 Answers