3

I have made a basic AR-app using Unity & Vuforia and exported it to Android, so I can add some activities there. When I scan the image with the AR-camera in the app, a model pops up. Nothing new there.

What I want to achieve, is that when a user taps a button in some activity, lets say the text on the button is "Elephant", the AR-camera in the app opens, scans the image and loads a model of an Elephant.

My question is: is this possible? Is it possible to load a model depending on the user-input? And if this is possible, what would be the best place to search for some documentation about it? I've already searched on the internet, but can't find anything this specific. I'm also new to Unity & Vuforia, so I don't know that much about the program. Only the things some tutorials covered.

My apologies if this question has already been asked/answered.

Thanks in advance!

1 Answer 1

8
+100

Well, yes it is possible. And to make your app really use the AR feature you can implement the Virtual Button technique.

Honestly, when it comes to documentation, Qualcomm is useless. But since you use Unity with the Vuforia Extension, most features are luckily within the Unity Documentation.

I'll explain how you can achieve this in two ways:

1. Using Virtual Buttons (VB)

First off, start by adding/dropping a VB onto the scene from Assets>Qualcomm>Prefabs>Virtual Button. Make sure the VB is a child of the Image Target used.

Create a new script for the Image Target that defines what your VB needs to do.

You'll start with registering the buttons:

void Start () { VirtualButtonBehaviour[] vbs = transform.GetComponentsInChildren<VirtualButtonBehaviour> (); for (int i=0; i < vbs.Length; ++i) { vbs[i].RegisterEventHandler(this); } 

And now you go ahead and start with the function of the button

public void OnButtonPressed(VirtualButtonAbstractBehaviour vb){ //specify which button you want to function by using the if statement if(vb.name=="ButtonName") { callButtonfunction();} } 

Similarly if you want a button to do something on release:

public void OnButtonReleased(VirtualButtonAbstractBehaviour vb){ //specify which button you want to function by using the if statement if(vb.name=="ButtonName") { callButtonfunction();} } 

In case you want your button to control a Gameobject, then go ahead and declare the GameObject as a public variable in the class so that it can be accessed in the Inspector and assigned accordingly.

public GameObject human; 

Where GameObject is the variable type and human is the variable name that we use for reference

Now again, as per what you're trying to gain, there are two ways of assigning what the callbuttonfunction() can do.

  • Application.LoadLeve("Levelname")

This loads a new scene where the new object is loaded onto the same Image Target

  • Model.enabled(false) and Elephant.enabled(true)

This simply disabled the current model and enabled the Elepant Model. Setting these to public variables at the start of your class will make it easier to assign the models within Inspect element.

2. On-screen Buttons (OB)

  • If you want on-screen buttons, then just parent the button UI to the Camera and position in a particular corner of the screen or something.
  • Now if you function the button it will be within void Update() and you could use the scripting reference from Unity using the touch functions.

Really hope this helps you and everyone else who suffers from absolutely NO support from Qualcomm. Hit me up if you need more clarification.

Sign up to request clarification or add additional context in comments.

4 Comments

Very well answered @Augmented Jacob
Thank you very much! I can certainly use the Virtual Buttons in my project. I agree that there is very little documentation about Unity and Augmented Reality. But I still have a question left: is it possible to load a model within an Android app? So when I click on a button in an Android view (just a normal Android button), the AR-camera in the app opens and loads a corresponding model
Yes, it is possible. But the android app needs to be built along with the Vuforia.jar and Vuforia.so files that are generally used for to create Vuforia apps. If it is, then go ahead and simply enable the new model and disable the old one, so it appears the model changes on button touch. Since you're using Unity it automatically does add the Vuforia files, so you can proceed without a problem
Thank you very much for your answers! It all worked out.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.