- Home /
Question by
svaldenegro · Feb 22, 2014 at 08:16 PM ·
rigidbodytransform
How can I add Rigidbody to Transform? [.js]
I've tried a lot of ways to that, but I have compilation errors.
if (Input.GetButtonDown("Use"))
{
if (!grabbing) {
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), hit)) {
grabObject = hit.transform;
grabObjectPhysics = grabObject.GetComponent(Rigidbody);
Destroy(grabObject.GetComponent(Rigidbody));
grabObject.parent = this.transform;
}
grabbing = true;
}
else {
// Doesn't works "No appropriate version of 'UnityEngine.GameObject.AddComponent' for the argument list '(UnityEngine.Rigidbody)' was found."
//grabObjectPhysics = grabObject.gameObject.AddComponent<Rigidbody>();
grabObject.gameObject.AddComponent(grabObjectPhysics);
grabObject.parent = null;
}
}
Comment
Answer by robertbu · Feb 22, 2014 at 08:51 PM
You should be able to:
grabObject.gameObject.AddComponent(Rigidbody);
The commented out line is the C# generic version. You can do:
gameObject.AddComponent.<Rigidbody>();
...in Javascript, but the first line should work fine.
I'm confused. If grabObject is not null, then the code I posted should add a Rigidbody to the game object. That is your question. If you issue is more complex, then you need to spell the situation out clearly (perhaps as a new question). There is no 'grabObjectPhysics.is$$anonymous$$ematic = true|false' in this code.
Your answer
