How do I quit the game via dialogue?
-
- Posts: 28
- Joined: Sun May 28, 2023 8:30 pm
How do I quit the game via dialogue?
How do I have a dialogue option quit the game?
Re: How do I quit the game via dialogue?
Create a scriptableobject like so, it should be in a file called ApplicationBridge.cs
Then, in an asset folder, right-click => create => Game => Application Bridge
In your dialogue, select the user response that should quit the game, add an event
Press "plus", select your Application Bridge asset, then select "Quit" on it.
You can use this to call any function on any scriptable object from a dialogue entry.
You can of course name it however you want, like "QuitGame" or "GameExitBridge"
Code: Select all
[CreateAssetMenu(menuName = "Game/ApplicationBridge", fileName = "Application Bridge")]
public class ApplicationBridge: ScriptableObject
{
public void Quit()
{
Application.Quit();
}
}
In your dialogue, select the user response that should quit the game, add an event
Press "plus", select your Application Bridge asset, then select "Quit" on it.
You can use this to call any function on any scriptable object from a dialogue entry.
You can of course name it however you want, like "QuitGame" or "GameExitBridge"
Re: How do I quit the game via dialogue?
^ That's a good suggestion.
Alternatively, you can write a sequencer command:
SequencerCommandQuitGame.cs
Then set the dialogue entry node's Sequence field to: QuitGame()
Alternatively, you can write a sequencer command:
SequencerCommandQuitGame.cs
Code: Select all
using UnityEngine;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
public class SequencerCommandQuitGame : SequencerCommand
{
private void Awake()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
Application.Quit();
Stop();
}
}
}
-
- Posts: 28
- Joined: Sun May 28, 2023 8:30 pm
Re: How do I quit the game via dialogue?
Thank you both! Works a treat. I really appreciate the support.