Search Unity

How to code an UI button(with Exit funtion) in C#?

Discussion in 'UGUI & TextMesh Pro' started by garethlamyh, Aug 4, 2017.

  1. garethlamyh

    garethlamyh

    Joined:
    Jul 25, 2017
    Posts:
    5
    I am a beginner of Unity 3D. I am writing an android app, and my start menu have an exit button. My idea is just very simple: after users press the exit button, the application will close.
    I know Application.Quit() for quiting an app. But I just dont know how to detect a touch from user on a button and return the application.quit() method. Should I use sth like button.onclick or input.gettouch? Thanks!
     
  2. Dalmazo

    Dalmazo

    Joined:
    Mar 18, 2015
    Posts:
    4

    Hey garenthlamyh o/

    Take a look here:

    https://unity3d.com/pt/learn/tutorials/topics/user-interface-ui/ui-button?playlist=17111

    You have to create a public function and put it on a button, something like this:

    public void ExitApp()
    {
    Application.Quit();
    }


    in this video, you can see how to link a function to a button