android - Vuforia Unity3D : how to make on-screen close/back/quit button?

标签 android button unity-game-engine augmented-reality vuforia

我刚刚开始制作 AR 应用程序。

我做了第一个,正在工作,高兴极了。但我有一个问题:我不知道如何在屏幕上插入一个按钮,当用户点击(是的,点击,我想在 Android 上工作)时,该按钮将关闭应用程序。

因此,当我运行在 Unity 中制作的应用程序时,我只看到相机。我想在屏幕的一角放置一个按钮,该按钮将始终矗立在那里并关闭应用程序。我需要这个按钮,因为我无法使用“后退”按钮关闭应用程序。

我使用 Nexus 7 2013 (android 5.0),因为只有那里的应用程序才能工作。在 Galaxy S2 4.4.4 上我总是崩溃(无法运行,只有闪屏)。但这是另一个问题:)

最佳答案

我刚刚遇到了同样的问题并找到了答案。您实际上可以使用后退按钮关闭应用程序!我在这里找到答案https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/android-back-key-not-working-unity-extension-imagetarge

  1. create a new C# script in your assets
  2. rename it, and open it (the default MonoDevelop by Unity will be opened to edit the script)

  3. write this code into the script:

    public void Update () {

        if (Application.platform == RuntimePlatform.Android) {
    
            if (Input.GetKeyUp(KeyCode.Escape)) {
    
               //quit application on return button
    
               Application.Quit();
    
               return;
    
           }
    
        }
    
  4. save it, and you can close the editor

  5. in the 'hierarchy' tab, you can click on 'ImageTarget' component and then click the 'add element' in the inspector, then choose 'script' option and choose the script that you've just made (I choose 'ARCamera' component instead and it still works)

希望这有帮助,虽然我可能对你的项目来说太晚了,但我希望将来遇到同样问题的人能得到帮助:)

关于android - Vuforia Unity3D : how to make on-screen close/back/quit button?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27072138/

相关文章:

c# - 如何正确创建对 Unity 对象的引用?

unity-game-engine - 与 的幂相反

Android 应用程序需要 Google Play 服务更新 - 打开按钮而不是更新

android - 如何在Android中使按钮不透明?

android - 如何禁用Android应用程序中的按钮

css - Bootstrap,行中的中心按钮

c# - 使用 async/await 的技巧

android - 如何使用 Espresso 测试由 TaskStackBuilder 生成的 PendingIntent

c# - 如何在 C# 中使用 Xamarin 中的 CHECK_VOICE_DATA_PASS?

java - 如何在Adapter类之外更新RecyclerViewAdapter