Action on continue button

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
jrose1184
Posts: 67
Joined: Mon Jan 22, 2024 2:35 pm

Action on continue button

Post by jrose1184 »

Hi,

How do i detect when the continue button is pressed on the dialogue i want to call an animation state every time that button is pressed please.

Also when my game is in game over state i want to destroy all runnng dialouges is there a function that also?

thanks
User avatar
Tony Li
Posts: 23152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Action on continue button

Post by Tony Li »

Hi,

> How do i detect when the continue button is pressed on the dialogue i want to call an animation state every time that button is pressed please.

You can hook up your method to the continue button's OnClick() event -- or, if you're using StandardUIContinueButtonFastForward, you can make a subclass that overrides OnFastForward to also call your animation state. Alternatively, you can add a script to the Dialogue Manager that has an OnConversationLineEnd() method.

> Also when my game is in game over state i want to destroy all runnng dialouges is there a function that also?

Yes. Use DialogueManager.StopAllConversations();
jrose1184
Posts: 67
Joined: Mon Jan 22, 2024 2:35 pm

Re: Action on continue button

Post by jrose1184 »

Hi thanks. So i did what you said and added a sub class like so

Code: Select all

using UnityEngine;
using PixelCrushers.DialogueSystem;

public class CustomContinueButton : StandardUIContinueButtonFastForward
{
    private static Animator staticAnimator;
    private static string staticTriggerName = "talking";
    private static string staticSpeakerName = "LemonDemo";

    public static void Configure(Animator animator, string triggerName, string speakerName)
    {
        staticAnimator = animator;
        staticTriggerName = triggerName;
        staticSpeakerName = speakerName;
    }

    public override void OnFastForward()
    {
        base.OnFastForward();

        string currentSpeaker = DialogueManager.instance.CurrentActor != null 
            ? DialogueManager.instance.CurrentActor.name 
            : string.Empty;

        Debug.Log("CustomContinueButton: OnFastForward called by speaker: " + currentSpeaker);

        if (!string.IsNullOrEmpty(currentSpeaker) && currentSpeaker == staticSpeakerName)
        {
            if (staticAnimator != null)
            {
                Debug.Log("Triggering animation: " + staticTriggerName);
                staticAnimator.SetTrigger(staticTriggerName);
            }
        }
    }
}
and then when i start a converstion i call it like so

Code: Select all

     if (GameManager.instance.playerAttackedFirst && !battleManager.playerAttacked)
                {
                    battleManager.playerAttacked = true;
                    
                    DialogueLua.SetVariable("PlayerAttackedFirst", true);
                    
                    Animator playerAnimator = battleManager.lemon.GetComponent<Animator>();
                    
                    if (playerAnimator != null)
                    {
                        playerAnimator.SetTrigger("talking");
                    }
                    
                    CustomContinueButton.Configure(
                        playerAnimator,
                        "talking",
                        "LemonDemo" 
                    );
                    
                    DialogueManager.StartConversation("Battle Demo", battleManager.player, battleManager.lemon);
                }
but for some reason it returning the wrong actor. i have checked the tree and the actor is lemon and no cola. am i doing somthing rong here.
User avatar
Tony Li
Posts: 23152
Joined: Thu Jul 18, 2013 1:27 pm

Re: Action on continue button

Post by Tony Li »

Hi,

DialogueManager.currentActor will always be the conversation's actor (i.e., battleManager.player). If you want to get the transform of the current dialogue entry's speaker, use DialogueManager.currentConversationState.subtitle.speakerInfo.transform.
Post Reply