Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GameObject blockType; //set this to a prefab in the editor
- int objectsCreated = 0;
- //Loop this whole thing until we've created as many blocks as we want
- while (objectsCreated < desiredNumberOfBlocks) {
- //Pick a random position within some limits
- float blockX = Random.Range(leftLimit,rightLimit);
- float blockY = Random.Range(levelHalfHeight * -1,levelHalfHeight);
- float blockZ = levelDepth;
- vector3 blockPosition = new Vector3 ( blockX, blockY, blockZ );
- //Create the block at that position and remember its name
- GameObject block = Instantiate(blockType, blockPosition, Quaternion.identity) as GameObject;
- //Pick a random size within some limits
- float blockWidth =Random.Range(5,maxBlockWidth);
- float blockHeight = Random.Range(5,maxBlockHeight);
- float blockDepth = Random.Range(5,maxBlockDepth));
- //Make our block that size
- block.transform.localScale = new Vector3(blockWidth, blockHeight, blockDepth);
- //Note we've made another block, loop
- objectsCreated = objectsCreated + 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement