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;
}
}
1 Answer
1
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#.
so.. var myPrefab = Instantiate(myPrefab)? Or did you want Unity to create a prefab for you?
– Polinatorill try that ^^^^
– DryTearok so it instantiates it at 0,0,0 but i want it to instantiate where the raycast hits(also beside the next cube)
– DryTear