Page 1 of 1

Playing dialogue audio on selection

Posted: Thu Feb 18, 2016 2:27 am
by bakershah
I was wondering if there was a way to get audio clips to play if I just hover and highlight a dialogue option? I have my character speaking his thoughts depending on what he highlights in the selection during a conversation? if there is a way could you let me know? Thanks! Love using your system btw! :D

Re: Playing dialogue audio on selection

Posted: Thu Feb 18, 2016 1:06 pm
by Tony Li
Hi,

Yes, but it requires a little scripting. I'll describe one possible approach using Unity UI. If you're using a different GUI system, you can adapt the same idea.

In your dialogue database, add a custom field titled something like "Hover Sequence" to your response dialogue entry notes. Set it to a sequence such as "Audio(someThoughtsAudioClip)" where someThoughtsAudioClip is the name of an audio clip in a Resources folder.

Create a script with a method such as "PlayHoverSequence" and add it to your response buttons (or your response button template if you're using that style).

Code: Select all

public class HoverButton : MonoBehaviour {

    public void PlayHoverSequence() {
        // Get the response associated with the button:
        var response = GetComponent<UnityUIResponseButton>().response;
        
        // Set the response's Hover Sequence:
        var sequence = Field.LookupValue(responseButton.dialogueEntry.fields, "Hover Sequence");
        
        // Play the Hover Sequence:
        DialogueManager.PlaySequence(sequence);
    }
}
Add an Event Trigger component to the response button. Add a Pointer Enter event, and assign the PlayHoverSequence method.


How this works:

1. When the player hovers over the button, the Event Trigger > Pointer Enter event calls the PlayHoverSequence method.

2. The PlayHoverSequence method looks up the response associated with the button and plays its Hover Sequence.