Currently im doing a AR audio book which is when scan multiple image target the sound will play for each target. Im trying to do follow the tutorial given by Unity and vuforia but still no working. can u help me out.
This scene contains bird and tiger. When image bird is scan the bird sound will play also the tiger.
This is my code:
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Vuforia;
public class ImageTargetPlayAudio : MonoBehaviour,
ITrackableEventHandler
{
private TrackableBehaviour mTrackableBehaviour;
void Start()
{
mTrackableBehaviour = GetComponent<TrackableBehaviour>();
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>().Play();
}
else
{
// Stop audio when target is lost
GetComponent<AudioSource>().Stop();
}
}
}
And image attached is my hierarchy.
I adding this code into each image target.
Correct me if im wrong.