- Home /
disabling rigidbody2D via script
hi guys i want turn the rigidbody off via script ...and i try this
this.rigidbody2D.enabled = false ;
but this is the unity error
MissingFieldException: UnityEngine.Rigidbody2D.enabled Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates)
would anybody help me...
i also tried this to stop an enemy when it is killed, but it keeps moving until the gameobject gets destroyed (2f) rigidbody2D.is$$anonymous$$inematic = true;
Answer by robertbu · Feb 26, 2014 at 05:16 PM
The Rigidbody class does not have an enabled flag. The typical solution is to set the isKinematic flag. This will freeze the object in position.
rigidbody2D.isKinematic = true;
If you won't be using the Rigidbody in the future you can remove it:
Destroy(rigidbody2D);
thanx i could delete the Rigidbody2D component , but the problem is that i want use it in the next period of time , so would u tell me that how can i add it again i used these 2 codes but Unfortunately none of them worked..
this.AddComponent(Rigidbody2D);
this.AddComponent.<Rigidbody2D>();
...and thanx again
Remember to reset velocity rigidbody2D.velocity = Vector2.zero;
@robertbu Is there a way to disable the simulated box, this way it won't have colliders either?