I want to make a map out of single cubes (not just one big cube where i change the scale)
This is because i want to make an interactive map.
Someone told me i could do this with script and prefabs to make the map.
Now my question is, how do you do this? I can make the prefabs my own, but i’m for sure not experienced enough to make my own script, although i’m still learning and by every script i examine, it gets me further in understanding the scripts.
NOTE : Im using Javascript.
I used this script first but the problem with this one is that it will just generate random objects in a certain Min and Max coordinate i had given. this brings me problems like : holes in the floor and several objects that are standing in the same coordinates
var myCube : GameObject;
function Start()
{
// Let's store some minimum and maximum possible x,y and z values
// to position our cubes:
var minX : int = -20;
var maxX : int = 20;
var minY : int = 1;
var maxY : int = 1;
var minZ : int = -20;
var maxZ : int = 20;
// (you can fiddle with these numbers to change the range of possible spawn positions)
var totalCubes : int = 500; // Change this to whatever number of cubes you'd like to have on-screen
var rot : Quaternion = Quaternion.identity;
for(i=0; i<totalCubes; i++)
{
// Use Random.Range to grab randomized x,y and z values within our min/max ranges:
var randomX : int = Random.Range(minX, maxX);
var randomY : int = Random.Range(minY, maxY);
var randomZ : int = Random.Range(minZ, maxZ);
var pos : Vector3 = new Vector3(randomX, randomY, randomZ);
Instantiate(myCube, pos, rot); // Put a new cube on the screen using a randomized position
}
}
function Update()
{
}
Then i used this script but it would just take to long to set all the blocks, and because i wanted to make a map out of 40x40 cubes that means i had to set 1600 blocks manually.
var myCube : GameObject;
function Start()
{
// Store a bunch of different positions in an Array:
var aPositions : Array = [new Vector3(0,1,0),
new Vector3(1,1,0),
new Vector3(2,1,0),
new Vector3(3,1,0),
new Vector3(4,1,0)];
var rot : Quaternion = Quaternion.identity;
// Loop as many times as there are elements in the aPositions Array:
for(i=0; i<aPositions.length; i++)
{
Instantiate(myCube, aPositions*, rot); // Put a new cube on the screen using the i'th position*
}
}
I can use every kind of help - Hexer.