我刚刚开始制作 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
- create a new C# script in your assets
rename it, and open it (the default MonoDevelop by Unity will be opened to edit the script)
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; } }
save it, and you can close the editor
- 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/