level generation

hi there im trying to make a level generation script similar to cubefiled but i dont know how to start the script of could someone help me start it of

if i see it correctly on google, you want a plane, and based on the level there are cubes spread over the plane.

so you would need to add a script to some gameobject, which generates cubes at a position

var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = yourposition

when to run your script? well, after your level is loaded or, keeping it simple, in the “Start()” method of your script.

now the hard task beginns: where to place the cubes?

well, you could place the cubes at random positions. just say, placing 300 cubes in an area between (0, 0, 0) and (100, 0, 100) (so cubes are placed acros x-z-plane).

now you’ve got 2 problems: 1. its possible for cubes to spawn into each other and 2. your cubes are placed randomly, there is no real level, its just some random placed cubes, no start no end, no path to follow.

i’d recommend you checking out the tutorials-series here: https://unity3d.com/learn/tutorials/modules/advanced/scripting/procedural-cave-generation-pt1?playlist=17153

it should give you an idea of how you can procedually generate levels. in the tutorial they are making caves but you can use this knoweledge for your game too.

edit: dont think @KdRWaylander’s answer is useless or he’s a troll: get a sheet of paper draw possible levels your generate could/should create and find what they have in common. maybe you can generate some kind of graph to produce a level from? or whatever.