Custom Sequencer Wait Message

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
domopuff
Posts: 25
Joined: Fri May 13, 2022 2:26 am

Custom Sequencer Wait Message

Post by domopuff »

Hey Tony,

I wish to build a custom distance-based wait method for the sequencer.

Something like etc. SetActive(obj, true)->WaitInRange(player, distance).

How would I achieve something like this?
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Sequencer Wait Message

Post by Tony Li »

Hi,

Please see part 6 of the Cutscene Sequence Tutorials: Custom Sequencer Commands to get a general idea of how to write custom sequencer commands. Then duplicate SequencerCommandTemplate.cs, move it to your own folder, and rename it to something like SequencerCommandWaitInRange.cs.

The syntax of sequencer commands doesn't allow for "->WaitInRange()", but you can do something like:

Code: Select all

WaitInRange(obj, player, distance)->Message(PlayerIsInRange);
SetActive(obj, true)@Message(PlayerIsInRange)
or, if you'll only use this to activate GameObjects, you can write a command SequencerCommandActivateWhenInRange::

Code: Select all

ActivateWhenInRange(obj, player, distance)
I'll outline the first version. Briefly, you'd fill in the code for Start(), Update(), and possibly OnDestroy(). Something like:

Code: Select all

using UnityEngine;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandWaitInRange : SequencerCommand
    {
        private Transform obj;
        private Transform mover;
        private float distance;

        private void Start()
        {
            obj = GetSubject(0);
            mover = GetSubject(1);
            distance = GetParameterAsFloat(2);
        }

        private void Update()
        {
            if (Vector3.Distance(obj.position, mover.position) < distance)
            {
                Stop(); // We're in range.
            }
        }
    }
}
domopuff
Posts: 25
Joined: Fri May 13, 2022 2:26 am

Re: Custom Sequencer Wait Message

Post by domopuff »

Ah I see. Thank you for your help!
User avatar
Tony Li
Posts: 22104
Joined: Thu Jul 18, 2013 1:27 pm

Re: Custom Sequencer Wait Message

Post by Tony Li »

Glad to help!
Post Reply