Hi, I am trying to catch the event to play sound when the pattern is read. At the moment of reading the pattern, the TargetLoad event does not do any action to me. Below I leave the code to see if you can help me.
Thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using easyar;
public class Audiora : MonoBehaviour
{
public AudioClip otherClip;
public AudioSource audios;
private AudioSource[] allAudioSources;
private ImageTargetController controller;
void Start()
{
audios = GetComponent<AudioSource>();
AddTargetControllerEvents(controller);
}
private void AddTargetControllerEvents(ImageTargetController controller)
{
if (!controller)
{
return;
}
controller.TargetFound += () =>
{
Debug.LogFormat("Found target {{id = {0}, name = {1}}}", controller.Target.runtimeID(), controller.Target.name());
};
controller.TargetLost += () =>
{
Debug.LogFormat("Lost target {{id = {0}, name = {1}}}", controller.Target.runtimeID(), controller.Target.name());
};
controller.TargetLoad += (Target target, bool status) =>
{
allAudioSources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[];
foreach (AudioSource audioS in allAudioSources)
{
audioS.Stop();
}
if (!audios.isPlaying)
{
audios.Play();
}
Debug.LogFormat("Load target {{id = {0}, name = {1}, size = {2}}} into {3} => {4}", target.runtimeID(), target.name(), controller.Size, controller.Tracker.name, status);
};
controller.TargetUnload += (Target target, bool status) =>
{
Debug.LogFormat("Unload target {{id = {0}, name = {1}}} => {2}", target.runtimeID(), target.name(), status);
};
}
}