Turning Scripts On/Off on a Certain Dialogue Entry

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
bakershah
Posts: 31
Joined: Sun Oct 19, 2014 10:26 am

Turning Scripts On/Off on a Certain Dialogue Entry

Post by bakershah »

Hi Iv'e been using your system for very months now and quite enjoy it. One Thing that has been bugging me is getting scripts to run when a certain dialogue entry is initiated. I'm working on a RPG and while I'm in a conversation I want certain other things in the background to happen when you make a conversation choice e.x: Particles, audio, and certain objects to turn on and off. How can you link individual scripts with the dialogue system in simply getting them to enable or disable on a certain entry?
User avatar
Tony Li
Posts: 20835
Joined: Thu Jul 18, 2013 1:27 pm

Turning Scripts On/Off on a Certain Dialogue Entry

Post by Tony Li »

Hi! You can use sequencer commands for this.



Use SetEnabled() to enable or disable a script. For example, say you have a particle effect on a GameObject named "Fountain". To turn it on when a dialogue entry is initiated, set the dialogue entry's Sequence field to:



SetEnabled(ParticleSystem, true, Fountain)



The manual page describes what arguments are optional. If the particle effect is on the speaker, you can just use:



SetEnabled(ParticleSystem)



If the script is already enabled and you want to execute a specific method on it, use the SendMessage() sequencer command. For example, say the speaker has a spell-casting script with a Cast(string spellName) method.  Use this sequence command:



SendMessage(Cast, Fireball)



This is equivalent to the script code:

speaker.SendMessage("Cast", "Fireball", SendMessageOptions.DontRequireReceiver);

where 'speaker' is the GameObject speaking the current dialogue entry.
Post Reply