Page 1 of 1

How do I quit the game via dialogue?

Posted: Sat Jun 24, 2023 5:53 pm
by Eldritch_Horror
How do I have a dialogue option quit the game?

Re: How do I quit the game via dialogue?

Posted: Sat Jun 24, 2023 8:17 pm
by lgarczyn
Create a scriptableobject like so, it should be in a file called ApplicationBridge.cs

Code: Select all

  [CreateAssetMenu(menuName = "Game/ApplicationBridge", fileName = "Application Bridge")]
  public class ApplicationBridge: ScriptableObject
  {
    public void Quit()
    {
      Application.Quit();
    }
  }
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

Image

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?

Posted: Sat Jun 24, 2023 8:32 pm
by Tony Li
^ That's a good suggestion.

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();
        }
    }
}
Then set the dialogue entry node's Sequence field to: QuitGame()

Re: How do I quit the game via dialogue?

Posted: Sun Jun 25, 2023 11:39 am
by Eldritch_Horror
Thank you both! Works a treat. I really appreciate the support. :)