How to destroy an object if the player keeps touching it?

Hi guys! I am kind of new to programming and Unity. I want to make a game where if the player touches some objects,it will destroy them only if he keeps touching them. For example, if the player keeps touching a dirt block for 1.5 seconds,the block will be destroyed,but if the player goes away from the block in the meantime,the object won’t be destroyed.
Right now I have the following code applied to the player:

void OnCollisionEnter2D(Collision2D col) 
 {
    	if (col.gameObject.tag == "Grass" || col.gameObject.tag == "Dirt") 
    		{
    		    Destroy (col.gameObject,1.5f);
    		}
 }

This works just fine except the blocks will be destroyed even if the player moves away from it. How can I check if in the meantime the player left the object and it doesn’t have to be destroyed?
I am sorry for my bad english (it isn’t my native language) and if I didn’t provide enough info.

Use the OnCollisionStay2D function: https://docs.unity3d.com/ScriptReference/Collider2D.OnCollisionStay2D.html. It is called once per frame as long as the colliders are touching.

Add a float counter to your object, increment it by Time.deltaTime in the OnCollisionStay2D and reset it to 0.0f in OnCollisionExit2D.

You can create special classes to handle this (you can define in their own files or inside the same C# file)

// Handles a set of Destroyable blocks
public class BlockDestroyer
{
    private System.Collections.Generic.List<DestroyableBlock> blocks;
    public BlockDestroyer()
    {
        // The `8` gives the initial capacity
        // It is not the upper limit of the set
        blocks = new System.Collections.Generic.List<DestroyableBlock>(8) ;
    }

    public void Update( float deltaTime )
    {
        // Update each block and destroy if needed
        for (int index = blocks.Count - 1; index >= 0; index--)
        {
            if( blocks[index].Update( deltaTime ) )
            {
                blocks.RemoveAt( index ) ;
                blocks[index].Destroy() ;
            }
        }
    }

    public void AddBlock( GameObject gameObject, float time )
    {
        DestroyableBlock block = DestroyableBlock( gameObject, time );
        if( !blocks.ContainsKey( block ) )
            blocks.Add( block ) ;
    }

    public void RemoveBlock( GameObject gameObject )
    {
        DestroyableBlock block = DestroyableBlock( gameObject );
        if( blocks.ContainsKey( block ) )
            blocks.Remove( block ) ;
    }
}

// Handles a single destroyable block
public class DestroyableBlock : IEquatable<DestroyableBlock>
{
    private GameObject gameObject ;
    private float time ;
    private float destroyDelay;

    public DestroyableBlock( GameObject gameObject, float destroyDelay = -1 )
    {
        this.gameObject = gameObject;
        this.destroyDelay = destroyDelay;
        this.time = 0 ;
    }

    public bool Update( float deltaTime )
    {
        time += deltaTime ;
        return time > destroyDelay ;
    }

    public void Destroy()
    {
        Destroy( gameObject ) ;
    }

    public override bool Equals(object obj)
    {
        if (obj == null) return false;
        DestroyableBlock objAsBlock = obj as DestroyableBlock;
        return (objAsBlock != null) ? Equals(objAsBlock) : false;
    }

    public override int GetHashCode()
    {
        return gameObject.GetInstanceID();
    }

    public bool Equals(DestroyableBlock other)
    {
        if (other == null) return false;
        return GetHashCode() == other.GetHashCode();
    }
} 

Then, in your script class:

void Start()
{
    blockDestroyer = new BlockDestroyer() ;
}

void Update()
{
    blockDestroyer.Update( Time.deltaTime ) ;
}

void OnCollisionEnter2D(Collision2D col) 
{
    if (col.gameObject.tag == "Grass" || col.gameObject.tag == "Dirt") 
    {
        blockDestroyer.AddBlock(col.gameObject, 1.5f);
    }
}

void OnCollisionExit2D(Collision2D col) 
{
    if (col.gameObject.tag == "Grass" || col.gameObject.tag == "Dirt") 
    {
        blockDestroyer.RemoveBlock(col.gameObject);
    }
}

I know it’s a bit of work, but I believe this is something clear