Page 1 of 1

How to play a specific sound before every dialogue?

Posted: Wed Dec 07, 2016 8:19 am
by Ondatr
Before the start of any dialogue I need a particular sound to be played, depending on which conversant starts the dialogue.
For now I wrote AudioWait (mySound) in the Sequence field of Start node for each dialogue. How to code it for all issues at once?

Re: How to play a specific sound before every dialogue?

Posted: Wed Dec 07, 2016 10:43 am
by Tony Li
Hi,

Here are some suggestions:

Suggestion 1:
1. Add an Audio Source component to each NPC. Assign the sound that you would like to play. Untick Play On Awake and Loop.
2. Add a Dialogue System Events component to the NPC. Set the OnConversationStart event to play the Audio Source.

Suggestion 2:
1. Name the sounds according to the NPC names (e.g., "Adam", "Bob", "Charlie") and put them in a Resources folder.
2. Add this script (which uses script messages) to the Dialogue Manager:

PlayConversantGreeting.cs

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class PlayConversantGreeting : MonoBehaviour {
    void OnConversationLine(Subtitle subtitle) {
        if (subtitle.dialogueEntry.id == 0) { // Add AudioWait(npcName) to START
            subtitle.sequence += "; AudioWait(" + subtitle.listenerInfo.Name + ")";
        }
    }
} 

Re: How to play a specific sound before every dialogue?

Posted: Wed Dec 07, 2016 12:42 pm
by Ondatr
Hi,

Going "suggestion 1" route, the sound plays simultaneously with the start of dialogue, not before.

Didn't try the "suggestion 2" yet, is there a way to control volume and other parameters of an audio clip with AudioWait?

Re: How to play a specific sound before every dialogue?

Posted: Wed Dec 07, 2016 3:50 pm
by Tony Li
Hi,

If you want it to play before the start of the dialogue, suggestion 2 is the way to go. AudioWait() doesn't provide parameters for volume control, but you can set them on the NPC's Audio Source or write a custom sequencer command to do so. They're actually quite simple to write, and the Dialogue System comes with a starter template.

Re: How to play a specific sound before every dialogue?

Posted: Fri Dec 09, 2016 2:32 pm
by Ondatr
Thank you for the great asset and excellent support!

Re: How to play a specific sound before every dialogue?

Posted: Fri Dec 09, 2016 2:53 pm
by Tony Li
Happy to help! :)