How do I reference a rule tile?

I’ve been following a tutorial online about automatically generating tilemaps, and I want to use a rule tile as the tile for the world I’m generating, but there’s a problem. I don’t know how to reference a rule tile as a public variable. How do I do it?

RuleTiles are a subtype of TileBase. They can be referenced like so:

using UnityEngine;
using UnityEngine.Tilemaps;

public class TestScript : MonoBehaviour
{
   public Tilemap tilemap; // assign this in Inspector
   public TileBase tile; // assign this in Inspector (RuleTile or any other tile)
 
   void Update()
   {
        if (Input.GetMouseButton(0)) // if pressing down left mouse
        {
             var mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             mouseWorldPos.z = 0f; // zero z
             var cell = tilemap.WorldToCell(mouseWorldPos);
             tilemap.SetTile(cell, tile);
        }
   }
}

More: Unity - Scripting API: Tilemap

Finally, a trick you can do in an IDE like Visual Studio is to type “RuleTile” (instead of TileBase) and then press CTRL+. and it will try to find the namespace RuleTile is under in a popup.

Thanks a lot man! Imma see if this works :>