This article is mainly attributed to the great Gods of the AR Academy.
Original Link: original link
I'm here to make a supplement.
Implementation function: Scan to the recognition graph display model while playing the corresponding sound, remove the identification chart pause playback, and then recognition from the last place to start playback.
Basic Flow:
(1) Right-click on the blank of the hierarchy panel and select Create empty to make the null component (renamed to Audio_x).
On the audio_x component, right-select audio Sourse under Audio to add the audio Sourse component and rename it,
Drag the sound file into audio clip, and note that spatial Blend is best set to 3D, because the problem of space distance, not very good control, may cause your camera distance identification map too far, can not hear the sound.
(2) Drag the audio_x in step (1) to the corresponding imagetarget;
(3) Add a variable public audiosource audio to the Defaulttrackableeventhandler script on Imagetarget
Add the play and pause functions in the found and lost functions in the Defaulttrackableeventhandler script, respectively:
Play Code
if (!audio.isplaying)
{
audio. Play ();
}
Pause Code
if (audio.isplaying)
{
audio. Pause ();
}
Note: The most important point is here. This is I made a mistake, looked for a long time to find, do not know you will not forget, anyway, I have forgotten. is to add the audio Sourse component created in step (1) to the Defaulttrackableeventhandler script.
(4) If you get here successfully, you should be finished.
Note: 1. There must be an object in the scene with the audio Listener, otherwise you will not hear the sound, here Arcamera with.
2. The spatial blend option of the sound component is best set to 2D, so the volume size is not affected by the distance from the audio listener to the sound source.
The original paste has a demo project source code, you can download down to look.