Trigger an event on a single word in a dialogue conversation

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
ko_games
Posts: 29
Joined: Wed Jan 08, 2020 3:20 am

Trigger an event on a single word in a dialogue conversation

Post by ko_games »

Hi Tony,

In my game, I would like certain UI to appear when the dollar amount in the conversation is displayed. For example in the following sentence, "The purchase price was $100,000 (show UI on the screen for this $100,000) not a penny more, not a penny less." Is there a way to send an event off when a certain word in a sentence is displayed (like the $100,000 in the example above)?

Right now, I only know how to use the add scene event on that line of dialogue, but then the UI appears a little too early since it shows it at the beginning of the sentence before the dramatic reveal of the price mid-sentence.

Hopefully, that all makes sense. Thanks again!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger an event on a single word in a dialogue conversation

Post by Tony Li »

Hi,

The easiest way is to figure out how long you need to wait before showing the UI. Then use the Sequence field to show it at that time. For example, if it will take 1.5 seconds to get to that point in the typewriter, set the Sequence field to something like:

Code: Select all

{{default}}
SetActive(DollarsUI,true)@1.5
The {{default}} tells the dialogue entry node to also play the regular default sequence in addition to activating the GameObject named DollarsUI at the 1.5 second mark.

If you don't want to do that for some reason, here are some scripting options:

1. You can make a subclass of the typewriter effect (e.g., UnityUITypewriterEffect) and override some methods to extract a new token that you'd define. When the typewriter gets to that token, perform your action (e.g., show UI on screen).

2. This one might be simpler to implement than #1: Or you can write a short script with an OnConversationLine method. Define a string to recognize (e.g., "[showUI]"). In OnConversationLine, extract that tag, and identify the string that precedes it. Then set a timer to show the UI after the time it will take to type the preceding string. Call ConversationView.GetDefaultSubtitleDuration(string) to determine the time to wait.
ko_games
Posts: 29
Joined: Wed Jan 08, 2020 3:20 am

Re: Trigger an event on a single word in a dialogue conversation

Post by ko_games »

Thanks Tony. I think I got it figured out for now. If I get stuck I'll let you know. Appreciate your quick response as usual!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Trigger an event on a single word in a dialogue conversation

Post by Tony Li »

Glad to help! :-)
Post Reply