Search Unity

Question Android back press button to quit ARCamera

Discussion in 'AR' started by kels-, Nov 26, 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
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,058
    If the script is not on any object in the scene it will never execute. You can put it on any gameobject in the scene which is active.

    You can see if the code runs by using debug.log
     
    andyb-unity likes this.