Page 1 of 1
How do I write to script from dialogue option?
Posted: Thu Jan 03, 2019 7:15 pm
by Tank
For example if the player picks a certain dialogue option, how do I make it so when that option is selected, something happens in a script? I want this particular choice to dictate the background of the player. I've tried to use an event from the event tab when you have a conversation line selected but I can't drag the script I want to use.
Any help is appreciated.
Re: How do I write to script from dialogue option?
Posted: Thu Jan 03, 2019 8:07 pm
by Tony Li
Hi,
There are several options.
Using the OnExecute UnityEvent is not always the best option. Dialogue databases exist outside of scenes, so their UnityEvents can't point to anything inside a scene. You can point them to a ScriptableObject, however, as in
this example.
Other options:
Save the background in a custom field of the Player actor. Two advantages: (1) you don't have to write a script, and (2) it's automatically saved in saved games. To do this:
- Inspect the actor, expand All Fields, and add a custom field.
- Inspect the dialogue entry node, and click the "..." next to the Script field. Select Actor > (your field) > (value)
Use the SendMessage() sequencer command in the dialogue entry node's Sequence field to call a method on a GameObject's script(s).
Write a custom sequencer command. See
Cutscene Sequences and
Custom Sequencer Commands.
Register your script method with Lua. Then use it in the
Script field. See
Lua and
Registering Functions.