如何在屏幕上放置控件? [英] How do I put controls on screen?

查看:189
本文介绍了如何在屏幕上放置控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Unity/Vuforia进行一个项目,以为Android构建增强现实应用程序,并且需要一些帮助. 找到imagetarget时,屏幕上出现一个球. 我不知道如何使球移动. 我可以使用虚拟按钮,但正在寻找一种方法来在android屏幕上设置向前/向后/向左/向右按钮(或操纵杆),以控制球.

I am working on a project using Unity/Vuforia to build an Augmented Reality app for Android and need some help. I have a ball appear on screen when the imagetarget is found. I cannot figure out how to get the ball to move around. I can use virtual buttons, but am looking to find a way of having the forward/back/left/right buttons (or a joystick) on the android screen which will control the ball.

任何人都可以提供任何建议或为我指明正确的方向吗? 我一直在搜索数小时,只能找到有关虚拟按钮的教程. 没有什么能帮助我学会将它们显示在屏幕上.

Can anyone offer any advice or point me in the right direction? I've been searching for hours and can only find tutorials for virtual buttons. Nothing that will help me learn to put them onscreen.

提前谢谢!

推荐答案

最适合您的选择是使用Unity的UI系统.您可以在UI中添加许多不同的内容,例如按钮,滚动条,滑块,图片或文本.使用此功能,您可以为游戏构建自己的控件.您可以通过场景编辑器或代码添加UI元素.

The best option for you is probably using the UI system of Unity. You can add a lot of different things in the UI, like buttons, scrollbars, sliders, pictures or text. Using this you might be able to build your own controls for your game. You can either add the UI element through the Scene editor or through code.

添加按钮非常简单:

1,单击以添加画布

(在Unity5中,Unity意外将默认值设置为错误的值.您使用的唯一设置是这两个.)

(Unity accidentally made the defaults the wrong ones, in Unity5. The only settings you use are those two.)

2,单击以添加一个按钮

2, click to add a Button

您已完成-只需拖动您要通过按钮运行的任何功能.

You're done - just drag in any function you want run by the button.

在示例中,您将拥有一个类似于THIS的脚本:

In the example, you'd have a script like THIS:

public void SomeScript()
  {
  public void ClickedMainMenu()
    {
    a.PlayOneShot(clickSound, 3f);
    SceneManager.LoadScene("main_menu");
    }
  public void ClickedLevel()
    {
    a.PlayOneShot(clickSound, 3f);
    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }
  public void ClickedQuit()
    {
    a.PlayOneShot(clickSound, 3f);
    Application.Quit();
    }

只需在UI.Button Inspector面板中拖动并选择相关功能即可. (您先按"+",然后拖动.)

simply drag and select the relevant function, in the UI.Button Inspector panel. (You press "+" first, and then just drag.)

这篇关于如何在屏幕上放置控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆