- Home /
Disable Rigidbody ?
I manually created a ragdoll on the bones of a character , the bones are placed in him as a child objects.
I have a script for combat and when life reaches zero this script and I would like to activate the ragdoll when life ends .
Switch on and off I think it is enough to activate or deactivate the Rigidbody .
So I thought of this code , to take rigidbody children of my character because he has a rigidbody but I will not turn it off . But it gives the errorei what it depends on ?
var Health = 100;
var rigidbdy : Component[];
rigidbdy = GetComponentsInChildren (Rigidbody);
function Start()
{
rigidbdy.enabled=false;
}
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
rigidbdy.enabled=true;
}
}
function Dead()
{
Destroy (gameObject);
}
ERROR: "Enabled" is not a member of "UnityEngine.Component[]"
Answer by MrSoad · Dec 07, 2014 at 11:15 PM
Use the "isKinematic" property of a rigidbody to switch it on and off.
http://docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html
This is a weird comment, but it says you said something here 21 $$anonymous$$utes ago, but I can't see it. lol? :P
Answer by static_cast · Dec 07, 2014 at 11:42 PM
You need to disable each rigidbody by doing this:
var Health = 100;
var rigidbodies : Rigidbody[];
rigidbodies = GetComponentsInChildren(Rigidbody);
function Start()
{
for(var rgdbdy : Rigidbody in rigidbodies)
rgdbody.isKinematic = true;
}
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
for(var rgdbdy : Rigidbody in rigidbodies)
rgdbody.isKinematic = false;
}
}
function Dead()
{
Destroy(gameObject);
}
Not sure if this is what you wanted, but put those rigidbodies back on. XD
Your answer