Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

android - How do I put controls on screen?

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.

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

To add buttons for example is ridiculously easy:

1, click to add a Canvas

Note - always select "Screen Space Overlay" and "Scale with screen size"

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

2, click to add a Button

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

enter image description here

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();
    }

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...