Created
November 10, 2017 00:35
-
-
Save oismaelash/13e89db79567dcfc284b267c3d91e444 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Vuforia; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ImageTargetPlayAudio : MonoBehaviour, ITrackableEventHandler | |
{ | |
public TrackableBehaviour mTrackableBehaviour; | |
void Start() | |
{ | |
mTrackableBehaviour = GetComponent<TrackableBehaviour>(); | |
GetComponent<AudioSource>().enable = false; | |
if (mTrackableBehaviour) | |
{ | |
mTrackableBehaviour.RegisterTrackableEventHandler(this); | |
} | |
} | |
public void OnTrackableStateChanged( | |
TrackableBehaviour.Status previousStatus, | |
TrackableBehaviour.Status newStatus) | |
{ | |
if (newStatus == TrackableBehaviour.Status.DETECTED || | |
newStatus == TrackableBehaviour.Status.TRACKED || | |
newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED) | |
{ | |
// Play audio when target is found | |
GetComponent<AudioSource>().enable = true; | |
GetComponent<AudioSource>().Play(); | |
} | |
else | |
{ | |
// Stop audio when target is lost | |
GetComponent<AudioSource>().Stop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment