How do I use the tilemaps In-game

I want to use the tilemaps and pallets as an In-Game feature to create maps in real time. I am very basic at coding and I haven’t been able to find any tutorials for this.

This is what I have:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public class Paint_Tile : MonoBehaviour
{
    public Tile brush;
    public Tilemap currentTilemap;
    public KeyCode mouseLeft;

    //Paint a tile-cell with the selected tile
    private void Update()
    {
        // get current grid location
        Vector3Int currentCell = currentTilemap.WorldToCell(transform.position);

        // if a cell is selected with mouseleft
        if (Input.GetKey(mouseLeft))
        {
            // paint the selected tile with the brush
            currentTilemap.SetTile(currentCell, brush);
        }
    }
}

It just chooses the same vector3Int everytime (-11, 1, 0) and places just the one brush there. What am I doing wrong?

I got it to update the correct position with:

Vector3Int currentCell = currentTilemap.WorldToCell(Input.mousePosition);

But it still won’t paint on the cells

I tried having this script on an empty game object and then on the tilemap itself, I don’t think that matters though because the objects are public.
Is it a problem that the “Brush” I am referencing is not in the hierarchy?

You can check if the Tile “brush” has been set correctly with tilemap.GetTile(currentCell) == brush.

I believe the issue you could be having with the actual cell position. Input.mousePosition is based on the position of the mouse on your screen, not the world position. You may need to use Camera.ScreenToWorldPoint to convert this correctly.