Page 1 of 1

Call function in script right at the moment when choices appear.

Posted: Mon Jul 24, 2023 2:17 pm
by Spacepiratehacker54
Hi,
I would like to call a function with parameters (a string) of a script on a game object in the scene right at the moment when the choice menu appears, because I would like to instantiate a GameObject during the time the player is faced with the choice. How could this be realized? Thanks!

Re: Call function in script right at the moment when choices appear.

Posted: Mon Jul 24, 2023 3:50 pm
by Tony Li
Use a sequencer command. You can write a custom sequencer command to call your function, or -- if the function accepts no parameters or a string parameter -- you can use the SendMessage() sequencer command. For example, if your function is on a GameObject named "Hourglass" and the function is named "Flip()", you could use the command:

Code: Select all

SendMessage(Flip, , Hourglass)
There are two points at which you can use the sequencer command:

1. At the end of the preceding dialogue entry's Sequence.
2. Or add a Response Menu Sequence to the preceding dialogue entry and use it there.

I'll go with #1 for an example. Let's say you don't require the player to click a continue button to advance the conversation. Instead, you want to advance to the response menu as soon as the subtitle panel's typewriter finishes typing. Then set the preceding dialogue entry's Sequence to:

Code: Select all

required SendMessage(Flip, , Hourglass)@Message(Typed)
The "required" keyword guarantees that the command runs even if the player skips ahead somehow.

door1Or2.png
door1Or2.png (26.05 KiB) Viewed 113 times