Minecraft switch item script

Hey guys I’m currently making a game like minecraft and I have a build script here it is:
var blockLayer : LayerMask = 1;
var range : float = Mathf.Infinity;
var hit : RaycastHit;
var BlockTexture : Texture;

function Update () {
    if (Input.GetMouseButtonDown(0))
        Build();
    if (Input.GetMouseButtonDown(1))
        Erase();
}

function Build()
{
	if(HitBlock()){
		var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
		cube.renderer.material.mainTexture = BlockTexture;
		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);
}

I was wondering how do I make a switch item script so like if you press 2 it will switch to a different material.

The simple solution would be to use an Array of Textures. Then you can Check Inputs in your Update Function, IE:

function Update(){
   if (Input.GetKeyDown(KeyCode.Alpha1))
   {
      BlockTexture = (yourArrayOfTextures)[0];
   }
}

You could check the key presses (0-9) and change the block based on that.

function Update() { if (Input.GetKeyDown("0") { BlockID = 1; } if (Input.GetKeyDown("1") { BlockID = 2; } if (Input.GetKeyDown("2") { BlockID = 3; } if (Input.GetKeyDown("3") { BlockID = 1; } }

and just carry on until you add all the keys. Then you could use the BlockID so when you place a block if its BlockID 1 it places grass or if its BlockID 2 it places stone.