Texture attach by .jpg file using script

I wrote this script to create a Cube and give specific properties (I am an amateur so be kind)

`function Start ()

    var cube1 = GameObject.CreatePrimitive(PrimitiveType.Cube);
    cube1.transform.position = Vector3(3.237656, 264.153, 0.4185972);
    cube1.transform.localScale.y -= 0.7; 
    var shader1 = Shader.Find( "Diffuse" );
    cube1.renderer.material.shader = shader1;


I am looking for a way to attach image (.jpg) from my files to material. Any idea how can I do this

Your textures needs to be in a folder named Resources, under Assets folder.

Use Resources.Load.

// Assigns a texture named "Assets/Resources/glass" to a Plane.

function Start () {
var go = new GameObject.CreatePrimitive(PrimitiveType.Plane);
go.renderer.material.mainTexture = Resources.Load("glass");