Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Vickylance · Dec 26, 2014 at 10:44 PM · uiunity4.6

How do I create an Exit confirmation Pop up when I click the exit button?

The question is pretty straight forward…But also I want to make a pop up asking whether you want to exit of not with a yes or no button(I have got all the sprite assets for it) . When I hit yes it must close the application which I did it but I don’t get how to make the popup quote image visible and all the background menu items (such as play button etc) invisible and also I don’t know how to again make this exit pop up invisible when I hit No button and bring back my background UI items?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Paps O · Dec 27, 2014 at 06:22 PM

I made a small example for you

  1. attach the following script on a gameobject (the canvas for example)

  2. add to the root of your normal ui (a panel for example) a CanvasGroup component

  3. add to the root of your quit confirmation ui (a panel for example) a CanvasGroup component

  4. Link the two canvas group to the gameobject where you put the script

  5. For each button (Quit, Confirm yes, Confirm No) add in the Inspector a onclick event to the script corresponding method

  6. That is all i think (I tried to comment a bit the code for reference), I also made some screenshot just in case

    public class QuitHandler : MonoBehaviour { public CanvasGroup uiCanvasGroup; public CanvasGroup confirmQuitCanvasGroup;

          // Use this for initialization
             private void Awake()
             {
                 //disable the quit confirmation panel
                 DoConfirmQuitNo();
             }
     
             /// <summary>
             /// Called if clicked on No (confirmation)
             /// </summary>
             public void DoConfirmQuitNo()
             {
                 Debug.Log("Back to the game");
     
                 //enable the normal ui
                 uiCanvasGroup.alpha = 1;
                 uiCanvasGroup.interactable = true;
                 uiCanvasGroup.blocksRaycasts = true;
     
                 //disable the confirmation quit ui
                 confirmQuitCanvasGroup.alpha = 0;
                 confirmQuitCanvasGroup.interactable = false;
                 confirmQuitCanvasGroup.blocksRaycasts = false;
             }
     
             /// <summary>
             /// Called if clicked on Yes (confirmation)
             /// </summary>
             public void DoConfirmQuitYes()
             {
                 Debug.Log("Ok bye bye");
                 Application.Quit();
             }
     
             /// <summary>
             /// Called if clicked on Quit
             /// </summary>
             public void DoQuit()
             {
                 Debug.Log("Check form quit confirmation");
     
                 //reduce the visibility of normal UI, and disable all interraction
                 uiCanvasGroup.alpha = 0.5f;
                 uiCanvasGroup.interactable = false;
                 uiCanvasGroup.blocksRaycasts = false;
     
                 //enable interraction with confirmation gui and make visible
                 confirmQuitCanvasGroup.alpha = 1;
                 confirmQuitCanvasGroup.interactable = true;
                 confirmQuitCanvasGroup.blocksRaycasts = true;
             }
     
             /// <summary>
             /// Called if clicked on new game (example)
             /// </summary>
             public void DoNewGame()
             {
                 Debug.Log("Launch a new game");
             }
    
    

I hope it's clear enough alt text alt text


inspector1.png (167.4 kB)
inspector2.png (174.6 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vickylance · Dec 27, 2014 at 10:48 PM 0
Share

Wow Thanks man, for this awesome tutorial... Though I have achieved it somehow which kinda works but I will change it to this method because that one is definitely not a good method.... But actually now I have got into a bigger problem.. Can you please check my other question on the button issue I have posted and please let me know whether it is my software problem or my code???

avatar image ChristianLaLarsson · Feb 14, 2019 at 09:07 PM 0
Share

Thank you very much for the code and the guide, helped a lot! :)

avatar image
2

Answer by HugoZandel · May 08, 2015 at 08:45 PM

I would like to add an alternative answer but it will only work in a standalone player on desktops. The advantage here is that if you run in window mode the Windows close button will trigger OnApplicationQuit thus giving more feedback to the user.

This is not a copy/paste type of example but more of an alternate method to the above. You will still need to code stuff.

 public class ExampleClass : MonoBehaviour {
     private bool allowQuitting = false;
     void Awake() {
         DontDestroyOnLoad(this.gameObject);
     }
     void OnApplicationQuit() {
         //TODO : SHOW POPUP CONTAINING A YES BUTTON WITH 
         //Application.Quit() + change allowQuitting to true.
         if (!allowQuitting)
             Application.CancelQuit();
         
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Sanjay1987 · Jun 08, 2018 at 04:07 AM

@Paps O Thank you. Worked like a charm.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by unity_4zuHSdl8nHRlfQ · Nov 09, 2018 at 05:19 PM

awesome work but im have diferent code and gift effect fade

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;        
 
 public class exitConfirm : MonoBehaviour {
 
 public CanvasGroup uiCanvasGroup;
 public CanvasGroup confirmQuitCanvasGroup;
 
  private void Start () {
      
  }
 
     public void FadeIn()
     {
         StartCoroutine(FadeCanvasGroup(confirmQuitCanvasGroup, confirmQuitCanvasGroup.alpha, 1, .5f));
         confirmQuitCanvasGroup.blocksRaycasts = true;
     }
 
     public void FadeOut()
     {
         StartCoroutine(FadeCanvasGroup(confirmQuitCanvasGroup, confirmQuitCanvasGroup.alpha, 0, .5f));
         confirmQuitCanvasGroup.blocksRaycasts = false;
 
     }
 
     public IEnumerator FadeCanvasGroup(CanvasGroup cg, float start, float end, float lerpTime = 1)
     {
         float _timeStartedLerping = Time.time;
         float timeSinceStarted = Time.time - _timeStartedLerping;
         float percentageComplete = timeSinceStarted / lerpTime;
 
         while (true)
         {
             timeSinceStarted = Time.time - _timeStartedLerping;
             percentageComplete = timeSinceStarted / lerpTime;
 
             float currentValue = Mathf.Lerp(start, end, percentageComplete);
 
             cg.alpha = currentValue;
 
             if (percentageComplete >= 1) break;
 
             yield return new WaitForFixedUpdate();
         }
 
         print("done");
     }
 



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Override sorting not working? The canvas just freezes………zzzzz 0 Answers

How to create a gradient progress bar 3 Answers

[4.6] Visual Studio Tools and UnityEngine.UI reference 3 Answers

Unity UI 4.6 - Programmatically adding events - EventTrigger.delegates is null 0 Answers

Unity 4.6 UI - Ignore raycast -1 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges