Playing dialogue audio on selection

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
bakershah
Posts: 32
Joined: Sun Oct 19, 2014 10:26 am

Playing dialogue audio on selection

Post 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
User avatar
Tony Li
Posts: 22143
Joined: Thu Jul 18, 2013 1:27 pm

Re: Playing dialogue audio on selection

Post 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.
Post Reply