Log in or register to post comments

Tracker triggers Audio

January 9, 2017 - 5:54am #1

I have a number of Image Targets that, when recognised, play the Audio Source that's attached to it.

At the moment, it is set to cut off the previous audio and play the new one when a new Image Target is recognised.

However, what I want to do is detect if an Audio Source is playing on any Image Target and if it is, let that finish before recognising the and playing the new one.

My current script in the DefaultTrackableEventHandler which just overlaps the audio:

private AudioSource[] allAudioSources;

  public AudioSource VO;

  private CanvasGroup[] AllCanvas;

  public CanvasGroup Info;

  public Canvas Point;

private void OnTrackingFound()

  {

    Point.enabled = false;

    foreach (AudioSource audioS in allAudioSources) {

    if (!audioS.isPlaying) {

     foreach (CanvasGroup CanvaS in AllCanvas) {

      CanvaS.alpha = 0f;

      CanvaS.blocksRaycasts = true;

     }

     VO.GetComponent<AudioSource> ().Play ();

     Info.alpha = 1f;

     Info.blocksRaycasts = false;

     Renderer[] rendererComponents = GetComponentsInChildren<Renderer> (true);

     Collider[] colliderComponents = GetComponentsInChildren<Collider> (true);

    // Enable rendering:

     foreach (Renderer component in rendererComponents) {

      component.enabled = true;

     }

     // Enable colliders:

     foreach (Collider component in colliderComponents) {

      component.enabled = true;

     }

     Debug.Log ("Trackable " + mTrackableBehaviour.TrackableName + " found");

    } else {

    }

  }

   }

Log in or register to post comments