How to spawn a model with texture?

Hello people,

I'm working on this project and want to spawn a model with a texture when I press a button. I know how to use buttons and GUI. Just need help with spawning it and getting the texture on it.

Thanks

Ever since Code Sample fails for me;

function OnGUI () 
{

    if (GUI.Button (Rect (5, 80, 100, 30), "Button"))
    { }
}

Put your material and the object you want to spawn in the following variables (in the Inspector window):

var mySpawn: GameObject;
var myMaterial: Material;

Then in your button function above (assuming you are spawning at myPosition and myRotation):

var newObject: GameObject = Instantiate(mySpawn,myPosition,myRotation);
mySpawn.renderer.material = myMaterial;

if you have trouble locating the material on the new object, you can also use GetComponent() or GetComponentInChildren().