Forum rules - please read before posting.

Stop NPC speech whenever Player speaks.

I'd like a scripted way to ensure that whenever my player talks he shuts down (stops speech) background NPC loop? Thanks!

Comments

  • using UnityEngine;
    using AC;
    
    public class StopBackgroundSpeech : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnStartSpeech_Alt += StartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech_Alt -= StartSpeech; }
    
        private void StartSpeech (Speech speech)
        {
            if (speech.GetSpeakingCharacter () == KickStarter.player)
                KickStarter.dialog.KillDialog (true, true, SpeechMenuLimit.BackgroundOnly);
        }
    
    }
    
  • Would this on a game object in first scene, or relevant scene? Thanks!

  • The relevant scene.

  • Thanks, is there also a way to stop a certain action list to run until the player has stopped speaking? I have a background NPC dialogue loop that runs, but i starts up again whilst the player is speaking, even though the above script stops it when the player speaks, not long into the PLayers convo the bg dialogue loop starts up whilst the player is speaking.

  • edited February 2023

    You can call an ActionList's Kill method to stop it running:

    using UnityEngine;
    using AC;
    
    public class StopBackgroundSpeech : MonoBehaviour
    {
    
        public ActionList[] actionListsToStop;
    
        private void OnEnable () { EventManager.OnStartSpeech_Alt += StartSpeech; }
        private void OnDisable () { EventManager.OnStartSpeech_Alt -= StartSpeech; }
    
        private void StartSpeech (Speech speech)
        {
            if (speech.GetSpeakingCharacter () == KickStarter.player)
            {
                KickStarter.dialog.KillDialog (true, true, SpeechMenuLimit.BackgroundOnly);
                foreach (ActionList actionListToStop in actionListsToStop)
                    if (actionListToStop) actionListToStop.Kill ();
            }
        }
    
    }
    
  • Thanks, how do I choose a specific Action list to stop please?

  • Assign it in the Inspector.

  • So I am just seeing this? Nowehre to put which action list in inspector?

    https://drive.google.com/file/d/1CzD3KKqq6PofjUb6hKxqeg5PjMFxyiEZ/view?usp=sharing

  • Have you updated your script with the second above?

  • my bad, it worked. Is it possible to adapt script so I can stop more than one action list please?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.