Home>

1 premise
I'm trying to create an AR using Vuforia and Unity. Since I was able to display the object using the marker, I am trying to use something called VirtualButton and am working on it.
The version of Unity is 2019.3.10f1.

2 problems
I investigated variously to use VirtualButton, but it did not respond well. I don't know what is the cause, so I will post both the scene view and the script attached to the button.

The image below is the scene view. ClickScript is a script that describes the processing when a button is pressed.

The image below is a script.

using System.Collections.Generic;
using UnityEngine;
using Vuforia;
public class clickScript: MonoBehaviour,IVirtualButtonEventHandler
{

    // Start is called before the first frame update
    void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {
    }
    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Debug.Log("Pressed");
    }

    public void OnButtonReleased(VirtualButtonBehaviour vb)
    {
        throw new System.NotImplementedException();
    }
}
code

When I saw various sites, it was written that the method called OnButtonPressed() can detect that the button was pressed, so when the method called OnButtonPressed is called Debug.Log(" It is as "Pressed").

However, even if I hide the button displayed in AR, it was not Debug.Log.

I don't know anything about Vuforia yet, so I would appreciate it if you could teach me.

  • Answer # 1

    I'm sorry that it's about sharing the reference URL, but isn't the procedure in the following tutorial helpful?
    *Ignore the process of rotating the Cube, and it seems to be helpful from around 2 minutes 30 seconds of the video.

    How to create Virtual buttons with Vuforia AR&Unity3D


    Here are some of the key differences from your code as compared to the tutorial above.
    *Please note that not all differences are listed.

    1. Virtual buttons are created from ImagegeTarget instead of normal [UI>Button].
    (There may be other generation methods, but I think it's just that it's not a normal UI button.)
    AddVirtualButton

    2. The event registration process is omitted due to the process in the script.

    void Start () {
            // Change the name of GameObject("LacieBtn") accordingly
            vbBtnObj = GameObject.Find("LacieBtn");
            // ↓ Without this processing, the "OnButtonPressed" event may not be called.
            vbBtnObj.GetComponent<VirtualButtonBehaviour>().RegisterEventHandler(this);
     }