Page 1 of 1
Custom Sequencer Wait Message
Posted: Wed Sep 18, 2024 2:22 am
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?
Re: Custom Sequencer Wait Message
Posted: Wed Sep 18, 2024 7:50 am
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.
}
}
}
}
Re: Custom Sequencer Wait Message
Posted: Wed Sep 18, 2024 11:17 am
by domopuff
Ah I see. Thank you for your help!
Re: Custom Sequencer Wait Message
Posted: Wed Sep 18, 2024 11:30 am
by Tony Li
Glad to help!