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;



However i cant seem to add the local created RigedBody, can someone help me?

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;