Minigames and puzzles
Minigames and puzzles
Hi
New here.
I am creating a visual novel - based on the demo scene.
The conversation has a continue button to move forward.
I want to add interactive elements and minigames inside the conversation.
i.e. npc says: try to hack the code and then a minigame should appear. at the end of the minigame I want to continue the conversation.
Btw I am using scene events to call for the games to start, but the conversation is still happening regardless.
What is the best way to set it up?
Thank you
Aviv
New here.
I am creating a visual novel - based on the demo scene.
The conversation has a continue button to move forward.
I want to add interactive elements and minigames inside the conversation.
i.e. npc says: try to hack the code and then a minigame should appear. at the end of the minigame I want to continue the conversation.
Btw I am using scene events to call for the games to start, but the conversation is still happening regardless.
What is the best way to set it up?
Thank you
Aviv
Re: Minigames and puzzles
Hi Aviv,
Set the dialogue entry's Sequence to:
When your minigame is done, use the C# method:
Some other options/variations:
Set the dialogue entry's Sequence to:
Code: Select all
Continue()@Message(FinishedMinigame)
Code: Select all
PixelCrushers.DialogueSystem.Sequencer.Message("FinishedMinigame");
Some other options/variations:
- If you want to make the player click continue before starting the minigame, and hide the dialogue UI while playing the minigame, add an empty dialogue entry after the "try to hack" entry, and set its Sequence to something like:
Code: Select all
SetDialogueUI(false); required SetDialogueUI(true)@Message(FinishedMinigame); Continue()@Message(FinishedMinigame)
- An alternative to using a scene event is to write a custom sequencer command that waits until the minigame is done. Then you could set the Sequence to something like:
Code: Select all
PlayHackingMinigame()->Message(FinishedMinigame); Continue()@Message(FinishedMinigame)
Re: Minigames and puzzles
One more question regarding this.
A Game Manager object handles all the mini games. I am using the Scnene Events in the dialogue entry to call them.
It worked well as long as I had one scene. I implemented the Visual Novel structure that contains two scenes (Start and Gameplay) and it seems the events are not registering.
All the games are in the template canvas under the Dialogue Manager (in both scenes)
My question is, basically - how do I run a C# method from the dialogue (i.e. GameManager.StartPuzzle())?
Thank you!
A Game Manager object handles all the mini games. I am using the Scnene Events in the dialogue entry to call them.
It worked well as long as I had one scene. I implemented the Visual Novel structure that contains two scenes (Start and Gameplay) and it seems the events are not registering.
All the games are in the template canvas under the Dialogue Manager (in both scenes)
My question is, basically - how do I run a C# method from the dialogue (i.e. GameManager.StartPuzzle())?
Thank you!
Re: Minigames and puzzles
Hi,
This is one of the reasons for registering C# methods with Lua or using (custom) sequencer commands. They're not tied to a specific scene. This page has an explanation of the pitfalls of using UnityEvents when going across scenes: How To: Manage Player Controls and Scene Changes.
Say your GameObject is a singleton with a C# method PlayMinigame1(), like:
You could register PlayMinigame1() with Lua:
and then call PlayMinigame1() in the Script field of a dialogue entry.
This is one of the reasons for registering C# methods with Lua or using (custom) sequencer commands. They're not tied to a specific scene. This page has an explanation of the pitfalls of using UnityEvents when going across scenes: How To: Manage Player Controls and Scene Changes.
Say your GameObject is a singleton with a C# method PlayMinigame1(), like:
Code: Select all
public class GameManager : MonoBehaviour
{
public static GameManager Instance {get; private set;} = null;
void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnThis(this.gameObject);
}
else
{
Destroy(this.gameObject);
}
}
public void PlayMinigame1() { ... }
Code: Select all
public class GameManager : MonoBehaviour
{
public static GameManager Instance {get; private set;} = null;
void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnThis(this.gameObject);
Lua.RegisterFunction(nameof(PlayMinigame1), this, SymbolExtensions.GetMethodInfo(() => PlayMinigame1()));
}
else
{
Destroy(this.gameObject);
}
}
public void PlayMinigame1() { ... }
Re: Minigames and puzzles
Thanks.
That worked perfectly.
Can I also pass variables from the conversation to my code?
i.e. "PlayGame(1)"
That worked perfectly.
Can I also pass variables from the conversation to my code?
i.e. "PlayGame(1)"
Re: Minigames and puzzles
Hi,
Yes. Use the DialogueLua class to access Dialogue System (Lua) variables in your C# code:
To give your dialogue database content, such as Conditions and Script fields, access to your C# variables, see Registering Lua Functions and How To: Connect C# Variables to Dialogue System's Lua.
Yes. Use the DialogueLua class to access Dialogue System (Lua) variables in your C# code:
Code: Select all
int score = DialogueLua.GetVariable("Score").asInt;