It sounds like you want to detect when the player first starts pointing at a tagged object. If thats the case I suggest you keep track of which object you are pointing at (in my code below this is selectedObject) and only fire your events if the object you are pointing is a different than what it used to be.
I haven't tested this code, but one solution may look like this:
using UnityEngine;
using UnityEngine.Events;
using System.Collections;
using Leap;
using Leap.Unity;
public class LeapRay : MonoBehaviour {
HandModel hand_model;
public UnityEvent OnHit;
Hand leap_hand;
public AudioClip[] audioClip;
public GameObject plane;
private LeapProvider provider = null;
private bool rayCaster = false;
GameObject selectedObject;
// Use this for initialization
void Start () {
hand_model = GetComponent();
provider = GetComponent();
leap_hand = hand_model.GetLeapHand();
if (leap_hand == null) Debug.LogError("No leap_hand founded");
}
// Update is called once per frame
void Update ()
{
for (int i = 0; i < 5; i++)
{
FingerModel finger = hand_model.fingers [i];
// draw ray from finger tips (enable Gizmos in Game window to see)
Debug.DrawRay (finger.GetTipPosition (), finger.GetRay ().direction, Color.red);
RaycastHit hit;
if (Physics.Raycast (finger.GetTipPosition (), finger.GetRay ().direction, out hit))
{
if (hit.collider.tag == "Plane" && hit.collider.gameObject != selectedObject)
{
selectedObject = hit.collider.gameObject
OnHit.Invoke ();
PlaySound (0);
Debug.Log (isHit);
lastHit = isHit;
}
}
else
{
selectedObject = null;
}
}
}
void PlaySound (int clip)
{
AudioSource audio = GetComponent ();
audio.clip = audioClip[clip];
audio.Play ();
}
}