- Home /
How do I have an event be triggered on an audio clip finishing playing?
Hi! In my game, I have a narrator. Oftentimes I want things to happen when the narrator finishes saying a line. Is there some sort of system in unity that lets me trigger events once the audio clip containing the narrator's line finishes playing? Currently, the only thing I can think of is using a timer set to the length of the audio clip, but that could prove to be annoying if I ever change the dialogue.
Answer by eses · Sep 08, 2018 at 07:09 PM
Hi @NeedUnusedName
Here's some pseudo code / logic:
- You could just get the Audio source clip length and store it, so no need to worry about length changing.
- You could create a coroutine, that takes the length as input parameter.
- Then make the coroutine wait until time matching the length of audio clip has passed.
- Finally, trigger whatever you need. This could also be an Action or a delegate that is another parameter that your coroutine takes.
Your answer
Follow this Question
Related Questions
How do you fill an EventTrigger from a script? 0 Answers
EventTrigger / EventListener (what's the difference?) 0 Answers
Event is not being implemented from interface 0 Answers
On Void Called 2 Answers
Pressing two on-screen buttons at the same time, with the same touch - Android Unity Event-Triggers 0 Answers