How to detect range of multiple gameobjects?

I am trying to create a script to where when the user comes within range of any of the objects, then the user may press “Spacebar” to open. I’ve searched for answers to similar questions but they don’t help. Mostly the code is just “Here it works trust me” so I can’t fully understand any of it because there is random spawn code and all that in the middle of what i need. And its not even in C#. Anyway. I need help with this, i’ve searched the references, answers, and just can’t find what I am looking for.

Concept: Player is within range, now we can do something(Place code there).

MyScript:

using UnityEngine;
using System.Collections;

public class TriggerDetection : MonoBehaviour
{

//--------------------------
    //Player's Position.
    public Transform player;
    
    //Set the range.
    int range = 20;
//--------------------------

    void Update()
    {
        //If the player comes within range of us.
        if (Vector3.Distance(transform.position, player) < range)
        {
            //Do something
            Debug.DrawLine(transform.position, player, Color.red);
        }
    }
}

Before you go too far down this road, why aren’t you using OnTriggerEnter?