Spawn an object when player is near and presses button

I have a spawn point that I would like to spawn an object from when the player is within a certain distance and presses the appropriate button. How would I go about this?

At the moment I just have the object spawning at Start:

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

public class ObjectSpawner : MonoBehaviour {

public GameObject DefenseShield;
public Transform Spawner;

private void Start()
{
    Instantiate(DefenseShield, Spawner.position, Spawner.rotation);
    
}

}
`

Thanks

I would add Colliders to both the player and the spawn point. Set the player collider to “Is Trigger” and then on the spawn point you can use the OnTriggerEnter() (or OnTriggerEnter2D() for a 2D application) method to detect a collision and spawn the object.

Something like this (not tested, just out of my mind):

public voin OnTriggerEnter2D (Collider2D other)
{
    if (other.tag == "Player") {
        if (Input.GetKeyDown(KeyCode.X)){
            // Instantiate here
        }
    }
}