Search Unity

2D Tilemap Extras - Rule Tile - Random

Discussion in '2D' started by Looping_co, Nov 21, 2022.

  1. Looping_co

    Looping_co

    Joined:
    Dec 10, 2016
    Posts:
    20
    I want to output random tiles but with a distribution / chance.
    Any possibilities to add percentage / weight for each tile of a random set ?

    Now I duplicate sprites but it's tedious.

    Thx,
    Vincent
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Looping_co likes this.
  3. Looping_co

    Looping_co

    Joined:
    Dec 10, 2016
    Posts:
    20
    Ok I moved the package and added the WeightedRandomTile folder and the WeightedRandomTile script but I don't know how to use it. I don't appear in the Assets>Create>2D>Tile menu. Do I have to add other files?
     
  4. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    I think it's missing a CreateAssetMenu attribute at the top. Make the top of the file look like this.
    Code (CSharp):
    1.     [Serializable]
    2.     [CreateAssetMenu(fileName = "New Weighted Random Tile", menuName = "2D/Tile/Weighted Random Tile")]
    3.     public class WeightedRandomTile : Tile
    4.     {
    5.         // blah blah blah
    6.     }
    Test that out and see if it gives you the weighted functionality you're looking for. If it does, then modifying the RuleTile and the RuleTileEditor to borrow the WeightedRandomTile's behavior would be the next step.
     
    StalemateZ likes this.
  5. Looping_co

    Looping_co

    Joined:
    Dec 10, 2016
    Posts:
    20
    Perfect! It works. Thank you.