Attaching an Model via Script.

So, while using C# I have to create a new GameObejct and apply Rigidbody as a component inside the script to use it…

How would I go about adding a model to this GameObject inside the script, without using the inspector.

Instantiate the model:

  Instantiate (prefab, new Vector3(0, 0, 0),Quaternion.identity);

parent it to your object with the script:

prefab.transform.parent = gameObject.transform;

I then suggest to zero out the position, rotation, and scale:

prefab.transform.localPosition = new Vector3(0,0,0);
prefab.transform.localScale = new Vector3(1,1,1);
prefab.transform.localEulerAngles = new Vector3(0,0,0);

GameObject newObj = new GameObject(“ObjectName”);
newObj.AddComponent ();

MeshFilter objMesh = newObj.AddComponent<MeshFilter>();
GameObject newMesh = Resources.Load("Cube") as GameObject;
objMesh.mesh = newMesh.GetComponent<MeshFilter>().sharedMesh;