Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Making prefabs for tilemaps

Discussion in 'Scripting' started by DangerKiddy, Dec 28, 2020.

  1. DangerKiddy

    DangerKiddy

    Joined:
    Feb 29, 2020
    Posts:
    8
    Hello, everyone! I have a tilemap(screenshot below) for my terrain.


    I want to randomly build on terrain some "prefabed" constructions, for example just a filled rect of special kind of block, and then palce some gameObjects in there.

    What I should to use, to easily make these prefabs and place them on tilemap, using script? I tried to do this only using code, but it will take too much time, to build more prefabs.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,769
    Tiles are actually not GameObjects or MonoBehaviours but rather just assets of type TileBase. They actually derive from ScriptableObjects.

    You can make these assets on disk, or make them at runtime and modify your TileMap with fresh tiles.

    You can also make your own classes derived from TileBase and code up more complicated behavior for a given tile. Check out the docs and maybe look for some tutorials on it.
     
  3. DangerKiddy

    DangerKiddy

    Joined:
    Feb 29, 2020
    Posts:
    8
    So, by default, I can't do anything, to place something on tilemap, and I need to code my own tool to create "prefabs" for tilemap?
     
    MuntyMcFly likes this.
  4. ink13

    ink13

    Joined:
    Nov 14, 2013
    Posts:
    37