How to generate random tile terrain at run time

I’m making a platform 2d game like mario.

Because I’m going to make a lot of stages, I need a random tile terrain generation method.

How do I generate terrain with a script at run time?

I even took a tile with a script, but I gave up because I couldn’t find a way to add a tilemapcollider2D

I am new to Unity and I am using a translator, so please understand.

You should be able to create a script that generate a Tilemap at runtime. There is multiple functions like Tilemap.SetTile or Tilemap.BoxFill that can add tile at runtime.


For your issue with the TilemapCollider2D, you should be able to create it before hand. The component will refresh itself whenever you modify the content of the Tilemap. Alternatively, you can use the GameObject.AddComponent function to add a component at runtime on a given GameObject.