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.