Destroy Tiles That Collide With Object

Hello! Sorry to ask a question that some others have asked but I have not seemed to be able to find a solution. Here’s what I have so far:

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

public class DestroyTilesOnCollision : MonoBehaviour
{

    public Tilemap tilemap;
    public ContactPoint2D[] contacts;

    void OnTriggerEnter2D(Collider2D collision)

    {

        if (collision.gameObject == tilemap)

        {

            collision.GetContacts(contacts);
            UnityEngine.Vector3 hitPosition = UnityEngine.Vector3.zero;
            foreach (ContactPoint2D hit in contacts)

            {

                hitPosition.x = hit.point.x - 0.01f;
                hitPosition.y = hit.point.y - 0.01f;
                tilemap.SetTile(tilemap.WorldToCell(hitPosition), null);
            
            }
        
        }
    
    }

}

Some additional information:

The way I am using this is by instantiating a game object with a circle collider 2D on it, which would then destroy the tiles it comes in contact with. (Is trigger is not enabled on the circle collider 2D since I understand that collision.GetContacts does not get any collision points if is trigger is enabled.) Other answers I have found on this subject use .contacts, but as that does not work, I believe that it has been deprecated, though I am not sure, and I know it causes a lot of memory garbage too. The documentation on .contacts says to use .GetContacts to reduce this. I replaced .contacts with setting an array to collision.GetContacts then using a foreach loop to iterate through that and disable the tiles.

Why is this not working? Any help is appreciated. Thank you!

@Tehemus
Got tile destruction working with this script:

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

public class DestroyTilesOnCollision : MonoBehaviour
{

    //public Tilemap tilemap;
    public ContactPoint2D[] contacts = new ContactPoint2D[10];

    public GameObject particles;

    public AudioSource explodeAndHitNoise;

    void OnCollisionStay2D(Collision2D collision)

    {

        Debug.Log("Hit!");

        if (collision.gameObject.name == "Tilemap")

        {

            Debug.Log("Hit tilemap!");

            int contactCount = collision.contactCount;
            if (contactCount > contacts.Length)
                contacts = new ContactPoint2D[contactCount];
            collision.GetContacts(contacts);


            UnityEngine.Vector3 hitPosition = UnityEngine.Vector3.zero;
            for (int i = 0; i != contactCount; ++i)

            {

                hitPosition.x = contacts*.point.x;*

hitPosition.y = contacts*.point.y;*
collision.gameObject.GetComponent().SetTile(collision.gameObject.GetComponent().WorldToCell(hitPosition), null);
var newParticles = Instantiate(particles, hitPosition, UnityEngine.Quaternion.identity);
var newSoundEffect = Instantiate(explodeAndHitNoise, this.transform.position, this.transform.rotation);
StartCoroutine(DestroyParticles(newParticles));

}

}

}

public IEnumerator DestroyParticles(GameObject particles)

{

yield return new WaitForSeconds(3f);
Destroy(particles);

}

}
A redditor helped me get this working from the script in the initial question. Here’s the reddit post: Reddit - Dive into anything
Thanks!