How to detect if two objects are touching?

I used the void OnCollisionEnter/Stay which did work but it worked if the object collided with another (for example if I moved cube1 and it hit cube2) while what I need right now is if cube1 is next to cube2 and is touching cube 2, then the action to happen.

Make your collider a little bigger, tag as trigger, change OnCollision to OnTrigger, and do a distance check with Vector3.Distance. The collider will now be the “is close” bool and the distance will be the “is touching” bool. Tweak the “maxDistance” to your liking when it looks like they are touching.

    public bool isTouching = false;
    public float maxDistance = 5;
    void OnTriggerStay(Collider other)
    {
        // other object is close
        if (Vector3.Distance(other.transform.position, this.transform.position) < maxDistance)
        {
            isTouching = true; // they are touching AND close
        }
        else {
            isTouching = false;
        }
    }