hello i basically got bored so i looked around for a minecraft type script and came across a Unity package and it was all there for you, but i dunno how to add a texture to the PrimitiveType.Cube, i tryed everything i know and it didnt work all i want is the choice to add a texture to the cube i create, it would be added multiple time in the scene this is why i need it to be in the code, here is the code
var blockLayer : LayerMask = 1;
var range : float = Mathf.Infinity;
var hit : RaycastHit;
var texture : Texture;
function Update () {
if (Input.GetMouseButtonDown(0)) Build();
if (Input.GetMouseButtonDown(1)) 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);
}
Thanks.