I am making a city builder type of game, and when a player creates a footpath, bridge, road, etc. how would I go about taking a prefab let’s say it is 1x1x1 units in size and repeat it as one game object.
So, lets say we are placing a bridge; when the player clicks a spot on the ground we start placement of the bridge, then when they move the mouse to the right we need to expand the bridge to that point, instead of stretching the bridge prefab, we will want make the prefab repeat. Is there a way to do this without making lots of game objects for each 1x1x1 section?
As far as I know, if you need to repeat the bridge mesh, you must either create another GameObject for each tile or modify the mesh at runtime. It is much easier to just clone the GameObject and it is possible to batch the drawing of static GameObjects sharing the same material so I think that would work well performance wise. I’d definitely try this method first and then fix any performance bottleneck much later.
Also, I think there are packages on the AssetStore that can build meshes on a curve path (Bezier or others) so that might be worth looking into if you need a quick solution.
I found some code on the unity website that will take a gameobject and all of it’s children and create one mesh from that. It is pretty simple, so I took that to modify it. Right now it is modifying buildings to create single mesh, but with a few tweaks I can do that for the bridge. Create an empty game object, and place bridge segments as children. When I confirm the size of the bridge fire off that script and it will create me a bridge as a single mesh with a collider!