Changing the rgb values of separate tiles

In my game you can place tiles on a tilemap on mouse click. I already have implemented placing tiles, but I also want to be able to change the color of tiles you are about to place. My code is here:

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

public class changergb : MonoBehaviour
{
    public static int r;
    public static int g;
    public static int b;

    void Start()
    {
        gameObject.GetComponent<SpriteRenderer>().material.color = new Color(r/255, g/255,b/255);
    }

    void Update()
    {
    
    }
}

My integers for r, g, and b are accessed from another script. I have no idea how to add this script to a tile, and I am not sure if my code would work on a tile as tiles do not have a sprite renderer.

Edit: I am also fine with instantiating gameobjects instead of tiles, just I have no idea how to make it so you can’t spawn multiple gameobjects on top of each other.

materials are shared, so if you change the shared material’s color… all your tiles using that material will change.
So you’d need one material per color you intend to use.

Or use UI Image instead of spriteRenderer, and you can set the color individually on Images.