Log in or register to post comments

How can i use the virtualbutton

March 19, 2012 - 7:35pm #1

Hi,i'm a begginer of QCAR with the Unity3D Extensions, i have some questions to ask you, i hope you can give me some advices, Thank you very much!

Here are my questions:
1. i have already installed the Unity3D Extensions in the Unity develop enviroment, i want create a sample like "VirtualButton" of QCAR, using the 3D model-"football",rolling it or some handle events like the "teapot", but i don't not how to do this. Can you help me? Give me a simple to tell me how can i to finish my sample? i'm a new coder.

2. With the VitualButton, Can i create some handle envent like "click the button, i can visit some website" or "click the button, the applicantion can interact with the server" and so on.

best regards
liujie023525:)

How can i use the virtualbutton

August 27, 2013 - 1:30am #45

Hello I have the same problem, look forward to your answer, how do I change the behavior of DefaultTrackableEventHandler,thanks very much

How can i use the virtualbutton

April 28, 2013 - 2:49pm #44

I have the same prob as the OP. I used his script below and it worked perfectly. I added it to a second target and it broke completely. I've even rolled back and added it again from scratch and it will no longer work...no matter what I try.

How can i use the virtualbutton

February 13, 2013 - 10:20am #43

Yup, the ImageTarget dataset is loaded and activated within the ARCamera Data Set Load Behaviour.

I'm sure it is something simple i've overlooked. 

 

 

How can i use the virtualbutton

February 12, 2013 - 1:05pm #42

Well you'll be happy to know that your event handler script works. I just tested it on the VB sample.

To confirm, are you loading and activating the ImageTarget's dataset within the ARCamera Data Set Load Behavior?

If that's not it, please PM me and I'll arrange to take a look at your project. It's probably something very simple.

How can i use the virtualbutton

February 12, 2013 - 12:51pm #41

Sigh. David, the virtual buttons still aren't doing anything. All the settings seem to be fine, the AR is set to the correct Image target 

Here is a screen shot of the Unity Inspector for the Image target. Maybe I'm missing something.

http://bmc1.erin.utoronto.ca/~andreaz/UnityEditorVB02.png

 

thanks so much for your help.

Andrea

How can i use the virtualbutton

February 12, 2013 - 12:29pm #40

Dont' worry about those warning.

Try setting the sensitivity on your buttons to high. You project looks OK.

How can i use the virtualbutton

February 12, 2013 - 12:22pm #39

http://bmc1.erin.utoronto.ca/~andreaz/UnityEditorVB.png

 

I noticed in the inspector the VirtualButtonBehavior Script didn't have a name so I added the name there...the error disappeared but the warnings still came up:

Assets/Qualcomm Augmented Reality/Scripts/Internal/BGRenderingBehaviour.cs(40,31): warning CS0618: `UnityEngine.GameObject.active' is obsolete: `GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.'

Assets/Qualcomm Augmented Reality/Scripts/Internal/BGRenderingBehaviour.cs(41,31): warning CS0618: `UnityEngine.GameObject.SetActiveRecursively(bool)' is obsolete: `gameObject.SetActiveRecursively() is obsolete. Use GameObject.SetActive(), which is now inherited by children.'

Would the obsolete coding affect this?

Any ideas? Let me know if you need anything else.

Andrea

How can i use the virtualbutton

February 12, 2013 - 11:41am #38

That's why I'd asked about the names, because the error suggests that the VB names are undefined in the Inpector.

Can you post a screen shot of your Unity Editor showing the scene and the hierarchy?

How can i use the virtualbutton

February 12, 2013 - 10:53am #37

Yes, they are children of the image target and yes I've named them.

cube_button

sphere_button

They are also 10% of the target image.

Do the buttons have to be children of the Game Objects?

I'm still not sure why it isn't working. Perhaps it has to do with the errors that pop up?

How can i use the virtualbutton

February 12, 2013 - 10:47am #36

Have you named your virtual buttons and are they children of the ImageTarget in the hierarchy?

Also be sure that they are at least 1/10 the area of the target and covering areas with trackable features - also be aware that there is a margin on the border of the target that it not detected.

How can i use the virtualbutton

February 12, 2013 - 10:16am #35

Hi!

I'm a newbie to scripting, familiar with some javascripting only and I'm still learning.

I've followed the steps in this thread using the below code saving it as VirtualButtonEventHandler. I've attached the script to the image target. I've named both game objects cube and sphere, as well as the buttons cube_button and sphere_button. When I build and run the app the sphere and cube appear but the virtual buttons have no effect.

These errors also pop up:

------

 

Duplicate virtual buttons with name 'undefined' detected in Image Target 'stones'.
UnityEngine.Debug:LogError(Object)
VirtualButtonEditor:DetectDuplicates(ImageTargetBehaviour) (at Assets/Editor/QCAR/Scripts/VirtualButtonEditor.cs:294)
VirtualButtonEditor:Validate() (at Assets/Editor/QCAR/Scripts/VirtualButtonEditor.cs:25)
SceneManager:EditorUpdate() (at Assets/Editor/QCAR/Scripts/SceneManager.cs:206)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
 

 

Assets/Qualcomm Augmented Reality/Scripts/Internal/BGRenderingBehaviour.cs(40,31): warning CS0618: `UnityEngine.GameObject.active' is obsolete: `GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.'
 
Assets/Qualcomm Augmented Reality/Scripts/Internal/BGRenderingBehaviour.cs(41,31): warning CS0618: `UnityEngine.GameObject.SetActiveRecursively(bool)' is obsolete: `gameObject.SetActiveRecursively() is obsolete. Use GameObject.SetActive(), which is now inherited by children.'
-----

Help/instructions would be incredibly appreciated. I'm using this for a graduate reserach project. I can send someone the file if needed.

 

using UnityEngine;
using System.Collections;

public class ButtonEventHandler : MonoBehaviour, IVirtualButtonEventHandler {

	public GameObject cube;
	public GameObject sphere;
	
	void Start()
    {
        // Register with the virtual buttons TrackableBehaviour
        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
        for (int i = 0; i < vbs.Length; ++i)
        {
            vbs[i].RegisterEventHandler(this);
        }

        cube = transform.FindChild("cube").gameObject;
        sphere = transform.FindChild("sphere").gameObject;
		
		sphere.renderer.enabled = false;
		
    }
    // Called when the virtual button has just been pressed:
    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonPressed");

        switch (vb.VirtualButtonName)
        {
            case "cube_button":
                Display( cube );
                Hide( sphere );
                break;

            case "sphere_button":
                Display( sphere );
                Hide( cube );
                break;


        }


    }
	
	public void OnButtonReleased(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonReleased");

        switch (vb.VirtualButtonName)
        {
            case "cube_button":
                break;

            case "sphere_button":
                break;


        }


    }

void Display( GameObject obj){

        Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

}


void Hide( GameObject obj ){

        Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }
}
}

 

How can i use the virtualbutton

November 3, 2012 - 9:10am #34

When using Unity, you can simply place the buttons in the Editor and they will be configured automatically. So you can remove that reference in your XML.

Have your removed teapot from your scene? That may be the cause of the error. Line 29 attempts to Find the original teapot model.

 

 

How can i use the virtualbutton

October 31, 2012 - 3:48pm #33

Hello, sorry for my English, I write through google translator)

I'm trying to deal with the virtual buttons. But I can not understand is obtained or not, do this:

create ImageTarget
make it a child prefab VirtualButton
add in the following xml goals
"<? xml version =" 1.0 "encoding =" UTF-8 "?>
<QCARConfig Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="qcar_config.xsd">
<Tracking>
<ImageTarget Size="90 50.037628" name="avers">
<VirtualButton Name="red" rectangle="-108.68 -53.52 -75.75 -65.87" enabled="true" />
</ ImageTarget>
</ Tracking>
</ QCARConfig> "
then attach on target VirtualButtonEventHandler (previously it removed three buttons leaving only one, because the one test)

but I have an error "NullReferenceException
VirtualButtonEventHandler.Start () (at Assets / Scripts / VirtualButtonEventHandler.cs: 29) "

help. immensely grateful.

Re: How can i use the virtualbutton

May 10, 2012 - 12:00am #32

thanks ksiva..

I've done as you suggested to me ..
I've replaced DefaultTrackableEventHandler with new scripts that I created ..

thanks for the advice ..

Re: How can i use the virtualbutton

May 9, 2012 - 9:09pm #31

sorry ksiva, I still don't understand the explanation..Can you give examples?

oh ya.. before getting that trouble, I've tried to use the toggle of mesh renderer. and when the application is started, it's work... but after I tried to create a new one, it did not work and its object is always visible.. why is that so?

Re: How can i use the virtualbutton

May 9, 2012 - 1:15pm #30

The DefaultTrackableEventHandler attached to the target also turns the renderers off and on (when the target is lost or found). You'll need to code around that, or change the behavior of the DefaultTrackableEventHandler.

- Kim

Re: How can i use the virtualbutton

May 7, 2012 - 5:47pm #29

thank you, i'll try it..

oh ya, i have problem.. I want to create virtual buttons to change the objects, for example, two VirtualButton, a cube and a sphere .. I would like if the first button pressed will appear the cube and if the second button pressed will appear the sphere .. I've given the example scripts by DavidBeard ( thanks DavidBeard :) ) and was succeeded..

The following arrangement of the window hierarchy:
- ARCamera
- ImageTarget
as childs of image target:
- cube
- cube_button
- sphere
- sphere_button

and this is a script as VirtualButtonEventHandler:

using UnityEngine;
using System.Collections;

public class ButtonEventHandler : MonoBehaviour, IVirtualButtonEventHandler {

	public GameObject cube;
	public GameObject sphere;
	
	void Start()
    {
        // Register with the virtual buttons TrackableBehaviour
        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
        for (int i = 0; i < vbs.Length; ++i)
        {
            vbs[i].RegisterEventHandler(this);
        }

        cube = transform.FindChild("cube").gameObject;
        sphere = transform.FindChild("sphere").gameObject;
		
		sphere.renderer.enabled = false;
		
    }
    // Called when the virtual button has just been pressed:
    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonPressed");

        switch (vb.VirtualButtonName)
        {
            case "cube_button":
                Display( cube );
                Hide( sphere );
                break;

            case "sphere_button":
                Display( sphere );
                Hide( cube );
                break;


        }


    }
	
	public void OnButtonReleased(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonReleased");

        switch (vb.VirtualButtonName)
        {
            case "cube_button":
                break;

            case "sphere_button":
                break;


        }


    }

void Display( GameObject obj){

        Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

}


void Hide( GameObject obj ){

        Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }
}
}

the problem is when the application is run and the marker is detected, the cube and the ball appeared both... I want the cube that appear the first time the marker is detected.. i have unchecked Mesh Renderer's Sphere in the inspector windows, but it doesn't work, the sphere always appear..

Re: How can i use the virtualbutton

May 7, 2012 - 2:10pm #28

Take a look at the DefaultTrackableEventHandler attached to each target in the samples. It contains a callback for OnTrackingFound and OnTrackingLost that you can use. I suggest copying that script and making a new one to attach to your trackable. You can add your OnGUI method to that.

- Kim

Re: How can i use the virtualbutton

May 7, 2012 - 12:42am #27

hmm.. I still do not understand the explanation of the link ..

Did you want to explain in detail? please help me.. :)

Re: How can i use the virtualbutton

May 6, 2012 - 3:16pm #26

You can either set a public property on the GUI script, which is checked in OnGUI, or enable/disable the component itself.

http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html

Re: How can i use the virtualbutton

May 6, 2012 - 9:11am #25

Hi, DavidBeard and Ksiva..
Thank you, I've successfully used the virtual button .. I want to ask, how to make GUI button that appear when ImageTarget detected?

i've created script for the GUI button and i attached it on the image target, but GUIButton appears when the application is running, not when ImageTarget detected..

this is a script that i created:

sing UnityEngine;
using System.Collections.Generic;

public class VirtualButtonEventHandler : MonoBehaviour
{

    public Material[] m_TeapotMaterials;

    private GameObject mTeapot;
    private List<Material> mActiveMaterials;

    void Start()
    {
        // Get handle to the teapot object
        mTeapot = transform.FindChild("teapot").gameObject;

        // The list of active materials
        mActiveMaterials = new List<Material>();
    }

	void OnGUI (){
        Debug.Log("OnButtonPressed");

        if (!IsValid())
        {
            return;
        }

       	GUI.Box(new Rect(10,10,100,150), "Button Menu");

	if(GUI.Button(new Rect(20,40,80,20), "Red")) {
		mActiveMaterials.Add(m_TeapotMaterials[1]);
	}

	if(GUI.Button(new Rect(20,70,80,20), "Green")) {
		mActiveMaterials.Add(m_TeapotMaterials[2]);
	}
		
	if(GUI.Button(new Rect(20,100,80,20), "Blue")) {
		mActiveMaterials.Add(m_TeapotMaterials[3]);
	}
		
	if(GUI.Button(new Rect(20,130,80,20), "Yellow")) {
		mActiveMaterials.Add(m_TeapotMaterials[4]);
	}
	
	if (mActiveMaterials.Count > 0)
            mTeapot.renderer.material = mActiveMaterials[mActiveMaterials.Count - 1];
    }

That script I created by modifying VirtualButtonEventHandler, I want the GUI button appears when ImageTarget detected .. What should I do?

Re: How can i use the virtualbutton

May 5, 2012 - 8:56pm #24

VirtualButton not appear on the marker as an example the following video: https://ar.qualcomm.at/qdevnet/developer_guide

oh ya, I ever get an error like the following:
[Quote" />Attempting to update a virtual button without a dataset
UnityEngine.Debug:LogError(Object)
VirtualButtonBehaviour:UpdateSensitivity(DataSet) (at Assets/Qualcomm Augmented Reality/Scripts/VirtualButtonBehaviour.cs:344)
VirtualButtonBehaviour:LateUpdate() (at Assets/Qualcomm Augmented Reality/Scripts/VirtualButtonBehaviour.cs:553)
[/Quote" />

I also tried to change the material, so that doesn't look transparent..but the virtual button still doesn't appear on the marker ..

Re: How can i use the virtualbutton

May 5, 2012 - 2:42pm #23

That looks fine.

What do you mean by 'the virtual button doesn't appear'?

VirtualButtons are invisible outside of the editor. The VirtualButton prefab is simply a tool for defining 'buttons' on targets. The tracker will recognize when these regions are being occluded and call the associated event handler.

Re: How can i use the virtualbutton

May 5, 2012 - 7:29am #22

yes, i know it.. i've tried the virtual button sample, but the virtual button still doesn't appear.. is something wrong when i put them in the hierarchy windows?
or can you give me some tutorial for the virtual button? please.. :)

can you check this screenshot for me?

Re: How can i use the virtualbutton

May 4, 2012 - 12:30pm #21

Run the virtual buttons sample and point your phone at the wood target. You should see a teapot. There are four buttons on the bottom of the target. If you touch one with your finger (in the real world, not on the device) the teapot color should change.

You can watch a video here (Samples/Virtual Buttons): https://ar.qualcomm.at/qdevnet/developer_guide

Note that the Unity version does not currently draw a box around the button, but the buttons should still work!

- Kim

Re: How can i use the virtualbutton

May 3, 2012 - 8:03pm #20

thanks for helping me, DavidBeard and Ksiva..

i have tried VirtualButtons sample but it still doesn't appear.. What should I do? is there something wrong with what I do? I've tried many times and I need this to make my task... :(

Re: How can i use the virtualbutton

May 2, 2012 - 8:16pm #19

You can find the sample here - https://ar.qualcomm.at/qdevnet/sdk

Install the appropriate version under Unity Extension and Release Notes. The samples are include w/ this release. This will also upgrade your Unity Extension to the current version. I think that you are working with an earlier version of the Unity Extension.

Once you've done this, you should be able to implement the script that I've provided without any problems.

* the version of the Unity Extension from the Unity Asset Store doesn't include these samples.

Re: How can i use the virtualbutton

May 2, 2012 - 7:18pm #18

where I can see an VirtualButtons sample? my Unity not have VirtualButtons sample?

i have attached VirtualButtonEventHandler to the target and the result is the same..

can you give me VirtualButtons sample to learn?

Re: How can i use the virtualbutton

May 2, 2012 - 7:17pm #17

where I can see an VirtualButtons sample? my Unity not have VirtualButtons sample?

i have attached VirtualButtonEventHandler to the target and the result is the same..

can you give me VirtualButtons sample to learn?

Re: How can i use the virtualbutton

May 2, 2012 - 3:11pm #16

The virtual buttons won't appear on the phone, typically you would design something into your target that looks like a button (see the wood target from the VirtualButtons sample).

I suggest taking a closer look at the VirtualButtons sample. You'll see that the VirtualButtonEventHandler is attached to the target, not the button.

- Kim

Re: How can i use the virtualbutton

May 1, 2012 - 6:21pm #15

i'm using unity extension 1.5.10 and unity 3.5, what i'm using the wrong version?
I also wonder why other people have the example of the virtual button's teapot, but I got nothing...

oh ya.. the VirtualButtonEventHandler's script doesn't error anymore.. but when i build to my phone, a cube and sphere both appear, but the virtual button doesn't appear.. What am I wrong to put in the windows hierarchy?

this is screenshot for my project:

[img" />http://s16.postimage.org/fu05ejae9/screenshot.jpg[/img" />[click to full image" />

please help :)

Re: How can i use the virtualbutton

May 1, 2012 - 8:07am #14

Which version of the Unity extension are you using?

add the following to make that error go away..

    public void OnButtonReleased(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonPressed");
		
        switch (vb.VirtualButtonName)
        {
            case "cube_button":
               // 
                break;

            case "sphere_button":
              //  
                break;
        }
    }

Re: How can i use the virtualbutton

April 30, 2012 - 9:19pm #13

but on the script folder does not exist VirtualButtonEventHandler, that there is VirtualButtonBehavior .. what scripts you give to me to add to the VirtualButtonBehavior? or I create a new VirtualButtonEventHandler?

edit:

I've created a new script VirtualButtonEventHandler contents as follows:

using UnityEngine;
using System.Collections;

public class VirtualButtonEventHandler : MonoBehaviour,IVirtualButtonEventHandler 
{
	
	private GameObject cube;
	private GameObject sphere;
	
	// Use this for initialization
	void Start()
    {
        // Register with the virtual buttons TrackableBehaviour
        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
        for (int i = 0; i < vbs.Length; ++i)
        {
            vbs[i].RegisterEventHandler(this);
        }

        cube = transform.FindChild("Cube").gameObject;
        sphere = transform.FindChild("Sphere").gameObject;
    }
	
    // Called when the virtual button has just been pressed:
    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonPressed");
		
        switch (vb.VirtualButtonName)
        {
            case "cube_button":
                Display( cube );
                Hide( sphere );
                break;

            case "sphere_button":
                Display( sphere );
                Hide( cube );
                break;
        }
    }
	

void Display( GameObject obj){
        Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }
}


void Hide( GameObject obj ){
        Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }
}
}

but I got an error like this:

Quote:

Assets/Qualcomm Augmented Reality/Scripts/VirtualButtonEventHandler.cs(4,14): error CS0738: `VirtualButtonEventHandler' does not implement interface member `IVirtualButtonEventHandler.OnButtonReleased(VirtualButtonBehaviour)' and the best implementing candidate `VirtualButtonEventHandler.OnButtonPressed(VirtualButtonBehaviour)' return type `void' does not match interface member return type `void'

Do you have a solution for this problem? thanks for your help :)

Re: How can i use the virtualbutton

April 29, 2012 - 8:51am #12

Implement it in the VirtualButtonEventHandler script attached to your target. IVirtualButtonEventHandler is an interface class that you can inherit from to develop custom event handlers.

e.g.
public class VirtualButtonEventHandler : MonoBehaviour,
IVirtualButtonEventHandler

You can find VirtualButtonEventHandler in your Scripts folder in the Project panel.

Re: How can i use the virtualbutton

April 29, 2012 - 2:07am #11

i'm still confused.. in the IVirtualButtonEventHandler only:

public interface IVirtualButtonEventHandler
{
     / / Called when the virtual button has just been pressed.
     void OnButtonPressed (VirtualButtonBehaviour vb);

     / / Called when the virtual button has just been released.
     void OnButtonReleased (VirtualButtonBehaviour vb);
}

Which part should I add the code that you gave? Can you explain in more detail?

thank you for your help :)

Re: How can i use the virtualbutton

April 28, 2012 - 9:54am #10

Take a look at the VirtualButtonEventHandler scripts in the VirtualButtons sample.

You can customize this code for your purposes..


    void Start()
    {
        // Register with the virtual buttons TrackableBehaviour
        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
        for (int i = 0; i < vbs.Length; ++i)
        {
            vbs[i].RegisterEventHandler(this);
        }

        cube = transform.FindChild("cube").gameObject;
        sphere = transform.FindChild("sphere").gameObject;
    }
    // Called when the virtual button has just been pressed:
    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonPressed");

        switch (vb.VirtualButtonName)
        {
            case "cube_button":
                Display( cube );
                Hide( sphere );
                break;

            case "sphere_button":
                Display( sphere );
                Hide( cube );
                break;


        }


    }

void Display( GameObject obj){

        Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = true;
        }

}


void Hide( GameObject obj ){

        Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();

        // Disable rendering:
        foreach (Renderer component in rendererComponents)
        {
            component.enabled = false;
        }
}

You would also want to implement whatever behaviors you need for the OnButtonReleased event.

Re: How can i use the virtualbutton

April 28, 2012 - 12:39am #9
ksiva wrote:

Take a look at the VirtualButtonEventHandler.cs script, in the Scripts folder of the VirtualButtons sample. The OnButtonPressed method handles each particular button press by name.

To open a web page on a button press, you could do something like this:

public void OnButtonPressed(VirtualButtonBehaviour vb)
{
    if (vb.VirtualButtonName == "red")
    {
        Application.OpenURL("http://www.google.com");
    }
}

- Kim

Hi, Kim.. I want to create AR with 2 virtual buttons and 2 object models .. suppose the object is a cube and a sphere, while pressing the first button will display the cube but the sphere undisplay, and when pressed a second button that would occur otherwise.

Can you give an example script, please? I'm newbie..

Re: How can i use the virtualbutton

April 26, 2012 - 8:16am #8

see my reply to your other post - http://ar.qualcomm.at/node/2002076

Re: How can i use the virtualbutton

April 26, 2012 - 6:22am #7

Hello ,
Im trying to make 3d objects to act like buttons .these objects are stitched to the target.How can i add touch event to those 3 D objects..
-Thank you
Mukundan G

Re: How can i use the virtualbutton

March 21, 2012 - 5:54am #6

:)Yes,you are right! I add the script on the wrong object, and when i add the script on the ImageTarget, the app is running.

Re: How can i use the virtualbutton

March 20, 2012 - 6:08pm #5

Hmm, it sounds like you did everything right. In the sample the VirtualButtonEventHandler is attached to the target instead of the button, but I think it should still work. Also you'll probably see a NullReferenceException in the log if you didn't modify the VirtualButtonEventHandler script (it's expecting a teapot object).

This error would typically occur if the button didn't have an ImageTarget as an ancestor. Are you sure it's a child of the target?

If you're still seeing problems please zip up the project and send to

, I'd like to take a look.

- Kim

Re: How can i use the virtualbutton

March 19, 2012 - 11:32pm #4

I :(
I use the virtualbutton example to create a application. when i run it it always show a error:
Attempting to update a virtual button without a dataset
UnityEngine.Debug:LogError(Object)
VirtualButtonBehaviour:UpdateSensitivity(DataSet) (at Assets/Qualcomm Augmented Reality/Scripts/VirtualButtonBehaviour.cs:344)
VirtualButtonBehaviour:LateUpdate() (at Assets/Qualcomm Augmented Reality/Scripts/VirtualButtonBehaviour.cs:553)

here is my App struct:
1.ARCamera
(the Active Data Set is "StonesAndWood",and the Load Data Set StonesAnd selected)
2.Directional light
3.ImageTarget
(Data Set is "StonesAndWood", ImagetTarget is wood)
4.add the virtualbutton as child on the ImageTarget and drag the VirtualButttonEventsHandler.cs onto this button

Is there sometihing i forgot to add into the applcation?

Re: How can i use the virtualbutton

March 19, 2012 - 7:51pm #3

1. The easiest approach is to simply substitute the elements in the samples for your own. For example to replace the targets with your targets, and the models with your models. You can use the samples as the basis for your own projects.

2. Here is a thread that describes how to achieve what you are asking - http://ar.qualcomm.at/node/2001646

Re: How can i use the virtualbutton

March 19, 2012 - 7:51pm #2

Take a look at the VirtualButtonEventHandler.cs script, in the Scripts folder of the VirtualButtons sample. The OnButtonPressed method handles each particular button press by name.

To open a web page on a button press, you could do something like this:

public void OnButtonPressed(VirtualButtonBehaviour vb)
{
    if (vb.VirtualButtonName == "red")
    {
        Application.OpenURL("http://www.google.com");
    }
}

- Kim

Log in or register to post comments