我通过使用 unity3d-vuforia 生成 .apk
创建了一个 android 应用程序。当我点击 back
按钮时,应用程序没有退出。我处理按下后退按钮。
我编辑由 unity 创建的 customEventHandler.cs
文件。
我的代码在这里:
using UnityEngine;
using System.Collections;
public class customEventHandler : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
// or ask to quit
}
}
}
我不确定是否可以添加它。我有一个二维标记和一辆虚拟汽车。汽车是 3d 对象。我检查事件处理程序,我的屏幕截图如下:
编辑
我使用下面的代码解决了这个问题。我不会删除这篇文章,因为解决方案可能会帮助某人。我编辑了 ImageTargetBehaviour.cs
文件。
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// This class serves both as an augmentation definition for an ImageTarget in the editor
/// as well as a tracked image target result at runtime
/// </summary>
public class ImageTargetBehaviour : ImageTargetAbstractBehaviour
{
void OnGUI () {
// call this block
if(Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
// or ask to quit
}
}
}
最佳答案
void Update(){
if (Input.GetKeyDown(KeyCode.Escape)){
Application.Quit();
}
}
http://answers.unity3d.com/questions/369198/how-to-exit-application-in-android-on-back-button.html
关于c# - Unity android应用程序不退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29599614/