The quick brown fox jumps over the lazy dog 551

The quick brown fox jumps over the lazy dog

Two options:

  1. Using OnMouseOver callback
// assuming that your object has collider and script is attached to that object
void OnMouseOver() {
        Debug.Log("mouse is over object");
    }
  1. Using Raycast (which is more generic way) - Unity - Scripting API: Physics.Raycast

The quick brown fox jumps over the lazy dog

Documentation contains JavaScript examples. For first solution, change “void” to “function”.

The quick brown fox jumps over the lazy dog

Put inside OnMouseOver function:

var distance : Vector3 = Vector3.Distance(this.transform.position,playerGO.transform.position);

if(distance<=requiredDistance)
{
    Debug.Log("player with in range and mouse is over the object");
}

The quick brown fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog

The quick brown fox jumps over the lazy dog

I’m sure that “Input.GetKeyDown(ButtonToPress)” will work in a OnMouseOver callback. It needs to be somewhere in Update().

The quick brown fox jumps over the lazy dog