How do you check if a game object is in the radius of another game object?

I am building a merging game where I want to check if a tower of the same kind is placed on the node beside the first one. Basically I want to check if a game object of the same kind is beside the current game object. I have tried different ways that I thought were familiar but have had no progress. (also, this happens within a button output).


My sort of script*


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

public class Merge : MonoBehaviour
{
    //a radius that covers 8 nodes
    public float nearTurret = 6f;
    //the prefab that is going to be merged
    public GameObject slingshot;

    //On click event =
    public void TowerMerge()
    {
        if () // < I don't know what to put here, what I want to do is (if slingshot is in radius of nearTurret) then ...
        {
            Debug.Log("Fuse towers");
        }
        else
        {
            Debug.Log("No tower near");
        }
    }

    //Radius Gizmos
    private void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.white;
        Gizmos.DrawWireSphere(transform.position, nearTurret);
    }
}

Hello there.

You need to calculate the distance between the 2 objects:

if (Vector3.Distance (Object1.tranform.position, Object2.tranform.position) < 100)
{
//Do something because the distance is less than 100
}

IF the number of towers in the map is not very big you can check for all other towers. If you have so many towers, You should create a Trigger collider to detect all towers inside the colliider, and then check for its distance to be sure.

Good Luck!