How would I change this Script to build a custom prefab instead of a Primitive Cube
function Build() {
if (HitBlock()) {
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = hit.transform.position + hit.normal;
}
}
function Build() {
if (HitBlock()) {
var myprefab = Instantiate(myPrefab, hit.transform.position + hit.normal, Quaternion.identity);
}
}
Unity documentation on Object.Instantiate, if what I gave isn’t exactly what you’re looking for. You might also want to move the declaration of myPrefab to the beginning of your script or in the Start() function, depending on if your code is JavaScript or C#.