How do I put textures on the blocks using a script?

I have a script that I need to place blocks. I’m trying to change the texture to something like Waterbump (you can find it in the assets)

Here’s the script:

var blockLayer : LayerMask = 1; 
var range : float = Mathf.Infinity; 
var hit : RaycastHit;
 
function Update () { 
if (Input.GetMouseButtonDown(1)) Build(); 
if (Input.GetMouseButtonDown(0)) Erase(); 
}
 
function Build() { 
if (HitBlock()) { 
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube); 
cube.transform.position = hit.transform.position + hit.normal; 
} 
}
 
function Erase() { 
if (HitBlock()) 
Destroy(hit.transform.gameObject); 
}
 
function HitBlock() : boolean { 
return Physics.Raycast(transform.position, transform.forward, hit, range, blockLayer); 
}

(yourgameobject).renderer.material.maintexture = “yourtexture.png”;, if not main texture, texture alone, cant remmember, intelissense is my lord

See the unity scripting reference,I think this would help you.

Scripting Reference