How to make object clickable when Player object is in specific distance?

Hi I want to make object clickable when Player object is in specific distance.
For detecting distance between Box object(which i want to make clickable) and Player object I use empty object.
So i want to make Box object clickable when empty object and Player object collided.

Here’s my code

using UnityEngine;
using System.Collections;

public class BoxHelp_Ctrl : MonoBehaviour {

private bool _clickable =false;

private GameObject BOX;

void Start()
{
			BOX = GameObject.FindGameObjectWithTag ("BOX");
	}

void OnTriggerEnter(Collider coll)
{
	if(coll.collider.tag =="Player")
	{
		Debug.Log("collision");
		_clickable =true;
	}
}

void OnMouseDown()
{if (_clickable==true) 
	Debug.Log ("click");

	}

void OnTriggerExit(Collider coll)
{
	if(coll.collider.tag=="Player")
	{
		Debug.Log("exit");
		_clickable =false;
	}
}

}

Plz help me!

What’s the problem with your solution ? It seems fine for me.

The Logs doesn’t appear ? Are you sure the “Info” button on the Console tab is activated ?

Otherwise, the solution of DoubleIsLoveDoubleIsLife may be more effective since it doesn’t require the use of a collider. Remove it and add the following code :

public class BoxHelp_Ctrl : MonoBehaviour {

    // From the inspector, add the player GameObject on this script's field
    public Transform Player ;

    // Exact same thing as player
    public Transform Box ;

    // Set the desired value
    public float InteractionDistance = 10 ;

    void OnMouseDown()
    {
        float distanceFromPlayer = Vector3.Distance( Box.position, Player.position ) ;

        if( distanceFromPlayer < InteractionDistance ) 
        {
            Debug.Log ("click");
        }
 
    }

}

Use Vector3.Distance(a,b) to find the distance between the player and the object, then test if they are close enough through an if statement.