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.
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");
}
}
}