Log in or register to post comments

Virtual Button EventHandler Problem

January 24, 2020 - 7:35am #1

(sorry for bad English) Hi, I'm working with a virtual button on AR that can show certain objects if the button pressed and do some loop. In December 2019 this virtual button seems well then I'm taking a break, but now I want to continue this project and now it doesn't work. This is my code. Thanks

 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;

public class vbPisces : MonoBehaviour

{

    GameObject fish1;

    GameObject fish2;

    GameObject fish3;

    VirtualButtonBehaviour vbPiscesNext;

    VirtualButtonBehaviour vbPiscesPrev;

    int obj=0;

    // Start is called before the first frame update

    void Start()

    {

        VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();

        for (int i=0; i < vbs.Length; ++i){

            vbs[i].RegisterOnButtonPressed(OnButtonPressed);

            vbs[i].RegisterOnButtonReleased(OnButtonReleased);

        }

        fish1 = GameObject.Find("fish1");

        fish2 = GameObject.Find("fish2");

        fish3 = GameObject.Find("fish3");

        fish2.SetActive(false);

        fish3.SetActive(false);

    }

    public void show(int input)

    {

        obj+=input;

        switch (obj)

        {

            case 1:

                fish1.SetActive(false);

                fish2.SetActive(true);

                fish3.SetActive(false);

            break;

            case 2:

                fish1.SetActive(false);

                fish2.SetActive(false);

                fish3.SetActive(true);

            break;

            case 3:

                fish1.SetActive(true);

                fish2.SetActive(false);

                fish3.SetActive(false);

            break;

            default:

            if(obj > 3)

            {

                obj=1;

            } else {

                obj=3;

            }

            show(0);

            break;

        }

       

    }

    public void OnButtonPressed(VirtualButtonBehaviour vb) {

        Debug.Log("pressed");

        switch (vb.VirtualButtonName)

        {

            case "vbPiscesNext":

                show(1);

            break;

            case "vbPiscesPrev":

                show(-1);

            break;

        }

    }

    public void OnButtonReleased(VirtualButtonBehaviour vb){

        Debug.Log("nope");

    }

    // Update is called once per frame

    void Update()

    {

    

    }

}

Virtual Button EventHandler Problem

February 3, 2020 - 4:26am #2

Hi,

We would need to debug the issue. I would first do a sanity check and confirm that the Button Press is registered. I see that you already added Debug information in the code.

Is the action registered? do you see "pressed" in the log after pressing the button?

Thank you.

Vuforia Engine Support

Log in or register to post comments