Is there an event which fires when player chooses a response

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
DragoonHP
Posts: 62
Joined: Tue Jan 15, 2019 8:17 am

Is there an event which fires when player chooses a response

Post by DragoonHP »

Can't find any such event in here > https://www.pixelcrushers.com/dialogue_ ... pting.html

Closest is OnConversationResponseMenu but it fires when the player is shown the menu
User avatar
Tony Li
Posts: 21948
Joined: Thu Jul 18, 2013 1:27 pm

Re: Is there an event which fires when player chooses a response

Post by Tony Li »

Try OnConversationLine. Even if the player's response isn't shown again as a subtitle, OnConversationLine will still be called.
DragoonHP
Posts: 62
Joined: Tue Jan 15, 2019 8:17 am

Re: Is there an event which fires when player chooses a response

Post by DragoonHP »

I wanted to know when the player clicks on a response. Is there a way to know that?
User avatar
Tony Li
Posts: 21948
Joined: Thu Jul 18, 2013 1:27 pm

Re: Is there an event which fires when player chooses a response

Post by Tony Li »

OnConversationLine will be called when the player clicks on a response. Example:

Code: Select all

public class OnConversationLine(Subtitle subtitle) {
    if (subtitle.speakerInfo.isPlayer) Debug.Log("Player chose: " + subtitle.formattedText.text);
}
Another way is to add to the OnClick() event of the response button(s). For example, you could add a script like this:

Code: Select all

public class LogWhenClicked : MonoBehaviour {
    void Awake() {
        GetComponent<UnityEngine.UI.Button>().onClick.AddListener(OnClick);
    }
    
    void OnClick() {
        var response = GetComponent<StandardUIResponseButton>().response;
        Debug.Log("Clicked: " + response.formattedText.text);
    }
}
The code above adds to the OnClick() event in code, but if you prefer you could instead assign it in the inspector.
DragoonHP
Posts: 62
Joined: Tue Jan 15, 2019 8:17 am

Re: Is there an event which fires when player chooses a response

Post by DragoonHP »

Thanks. :)
Post Reply