Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Unity back press button to quit the application

Discussion in 'General Discussion' started by kels-, Nov 25, 2022.

  1. kels-

    kels-

    Joined:
    Feb 26, 2022
    Posts:
    2
    Hi, i am stuck implementing the back button press to quit the unity 3D ARCamera. I have created new C# script with code

    -------------------------------------------------------------------------------------------------------------
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Quit : MonoBehaviour
    {
    public void Update()
    {

    if (Application.platform == RuntimePlatform.Android)
    {

    if (Input.GetKeyUp(KeyCode.Escape))
    {

    //quit application on return button

    Application.Quit();

    return;

    }

    }

    }

    }
    -------------------------------------------------------------------------------------------------------------

    I saw some old forum or answers from google telling that the script need to be add into ARCamera or any GameObject component. So i just follow their instruction but unfortunately the script is gone from the Inspector tab and also the GameObject missing from "hierarchy tab" after i export the Unity project into certain folder because i am working with Android Studio.

    I am confused and i dont know what should i do to make the back button quits the Unity application :(

    1.PNG 2.PNG 3.PNG