Get Response Index

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
ar4wy
Posts: 26
Joined: Fri Nov 15, 2019 10:16 pm

Get Response Index

Post by ar4wy »

Hi Tony!

I'm trying to get the response index. I'm trying to play a sound effect on button select, and want to know if I'm moving up or down in the menu.

I tried using the GetSiblingIndex(), but since the response menu creates new objects, it's not always correct when a new menu instantiates.

Could you show me a script where I could get the index of the available responses?

All the best!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Get Response Index

Post by Tony Li »

Hi,

There are a few ways you can do this.

1. You can add all your buttons to the Standard UI Menu Panel's Buttons list at design time instead of instantiating a template. Then you'll know their order ahead of time.

2. Or you can make a subclass of StandardUIMenuPanel and override ShowResponses. At the end of the method, set up your sounds:

Code: Select all

public override void ShowResponses(Subtitle subtitle, Response[] responses, Transform target)
{
    base.ShowResponses(subtitle, responses, target);
    // Add your code here. The instantiated buttons are in the instantiatedButtons list.
}
3. Or, if you don't want to subclass, add a new script to the Dialogue Manager that has an OnConversationResponseMenu method. Wait until the end of the frame, then set up your sounds:

Code: Select all

void OnConversationResponseMenu(Response[] responses)
{
    StartCoroutine(SetupSounds());    
}
IEnumerator SetupSounds()
{
    yield return new WaitForEndOfFrame();
    // Add your code here.
}
Post Reply