c# - Unity android应用程序不退出

标签 c# android unity-game-engine keyboard-events

我通过使用 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 对象。我检查事件处理程序,我的屏幕截图如下:

enter image description here

编辑

我使用下面的代码解决了这个问题。我不会删除这篇文章,因为解决方案可能会帮助某人。我编辑了 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/

相关文章:

c# - 与 Linq DataContext 通用

c# - 为什么这个正则表达式返回真?

c# - 如何从 KEY 文件导入 RSA key

android - 将 map 缩放到某个位置并将其向右 move

android - 如何在 android 中为纸板渲染 3d 视频?

c# - 在实现中用派生类覆盖接口(interface)方法返回类型

Android Maps API v2 - 在我的位置光标上单击事件

android - 为什么我的 Activity 没有看到观察到的物体变化?

java - Unity 插件在使用通知 Compat Builder 时出现错误

c# - Oculus Quest - 现实世界对齐