Setting Rule Tiles On Tilemaps In-Game

What I (would like) to do is to be able to set a rule tile on a tilemap in-game. Is that even possible? And do rule tiles even work in-game? If anyone knows, please inform me. If there is no solution, I could probably find another (albeit harder) solution to this. Thank you!

Yes, very possible: Unity - Scripting API: Tilemap

RuleTiles will refresh themselves and their neighbors, just like in the editor.

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);
        }
   }
}