![]() ![]() When you hit Escape, the dialog will pop up. ![]() If (Input.GetKeyDown(Ke圜ode.KeypadEnter) || Input.GetKeyDown(Ke圜ode.Return))Īnd that’s it. If the user hits enter, then quit application. If the UI is not showing, then if user hits escape, show the UI. Transform.Find("Image").Find("btn_OK").GetComponent().onClick.AddListener(QuitApp) Transform.Find("Image").Find("btn_Cancel").GetComponent().onClick.AddListener(HideUI) Transform.Find("Image").gameObject.SetActive(_isShowing) Public class UI_Exit_Script : MonoBehaviour The code here is super easy that an absolute novice in Unity/C# should be able to understand it relatively easily… Simples! Now for the code… Code…Īdd a new script to the UI_Exit Game Object called UI_Exit_Script and add the code below. I have set it up this way as the script that controls all of this is hosted to the UI_Exit Game Object, so to Show/Hide the UI all I need to do is turn on/off the Image Game Object. And the buttons and text are all children of the Image. The UI_Exit is an empty Game Object attached to the Canvas that has an Image as a child. Here is the Scene Hierarchy of the dialog… ![]() I remember when I first started using unity this was probably one of the first things I wrote… mostly because I got fed up with being in full screen post-build and there is no exit button thinking dammit…I forgot to make that dialog again! So I will quickly show a quick and dirty dialog for just that purpose… Setup…įor this UI I made a really simple dialog as shown below… Probably the most basic thing you can do with Unity… but, if you are super new to Unity and C# this is might be just the right thing to get you started… Quit Application… While I am on a roll, here is a very short Unity post. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |