- Home /
Question by
zahlio · Jun 20, 2014 at 03:20 PM ·
gameobjectrigidbodycreate
Adding local created rigedbody to gameobject
So ive tried severel of methods, non works. Here is my code:
GameObject temp_obj = GameObject.Instantiate(building, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
// Add components
Rigidbody r = new Rigidbody();
r.inertiaTensor = new Vector3(1, 1, 1);
r.useGravity = false;
temp_obj.AddComponent(r);
And:
temp_obj.AddComponent<r>();
However i cant seem to add the local created RigedBody, can someone help me?
Comment
Best Answer
Answer by robertbu · Jun 20, 2014 at 03:22 PM
You never use the 'new' operator with a Component. You just have to use AddComponent:
Rigidbody r = temp_objAddComponent<Rigidbody>();
r.inertiaTensor = new Vector3(1,1,1);
r.useGravity = false;
Yeah i figured it out, marking your suggestions as the answer though as it was basically what i did.
Your answer
Follow this Question
Related Questions
How to keep a GameObject inside a collider? 3 Answers
Placing a cube on the face of another 4 Answers
Unity3D Pressure Plate request. 3 Answers
Instantiate prefab to the parent 2 Answers