Answers for "unity android back button"

0

unity android back button

using UnityEngine.SceneManagement;

void Update()
{
    if (Input.GetKey(KeyCode.Escape))
    {
        SceneManager.LoadScene("Main Menu");
    }
}
Posted by: Guest on March-03-2021
0

unity android back button

public class RrAndroidBackButton : MonoBehaviour {
 
    public static RrAndroidBackButton instance;
 
    void Awake() {
        if (null == instance) {
            instance = this;
            DontDestroyOnLoad(this.gameObject);
        } else {
            Destroy(gameObject);
        }
    }
 
    void FiexdUpdate () {
        if (Application.platform == RuntimePlatform.Android){
            if (Input.GetKey(KeyCode.Escape)) {
                Application.Quit();
 
                System.Diagnostics.Process.GetCurrentProcess().Kill();
 
                AndroidJavaObject activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer")
                        .GetStatic<AndroidJavaObject>("currentActivity");
                activity.Call<bool>("moveTaskToBack", true);
            }
        }
    }
}
Posted by: Guest on March-03-2021

Code answers related to "unity android back button"

Browse Popular Code Answers by Language