Topic locked

Creating 2 Virtual Button in 1 scene

September 27, 2021 - 1:33pm #1

hi! I want to ask how to make 2 virtual buttons at once? I'm really confused about the "(variable name).GetComponent().RegisterOnButtonPressed(OnButtonPressed);" because I want to make 2 vb. this is my code, please correct me if something is wrong, pls help me, thank you.

 

public class VBManager : MonoBehaviour {

// private fields to store models

private GameObject sc_brosur;

private GameObject sc_video;

private GameObject btn_1;

private GameObject btn_2;

// memanggil scene ketika loaded

void Start() {

     // mencari child dari object ini yang memiliki script VirtualButtonBehaviour

     btn_1 = GameObject.Find("btn_info");

     btn_2 = GameObject.Find("btn_video");

    btn_1.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonPressed(OnButtonPressed);

    btn_1.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonReleased(OnButtonReleased);

    btn_2.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonPressed(OnButtonPressed);

    btn_2.GetComponent<VirtualButtonBehaviour>().RegisterOnButtonReleased(OnButtonReleased);

     // setelah tracking camera model bisa muncul ketika ditekan

     sc_brosur.SetActive(false);

     sc_video.SetActive(false);

     btn_1.SetActive(true); //vb brosur

     btn_2.SetActive(true); //vb video

    

}

/// <summary>

// memanggil objek ketika virtual button ditekan (eksekusi)

/// </summary>

public void OnButtonPressed(VirtualButtonBehaviour vb) {

     Debug.Log("Button pressed!");

     switch(vb.VirtualButtonName) {

         case "btn_info":

         btn_1.SetActive(true);

         btn_2.SetActive(true);

         sc_video.SetActive(false);

         sc_brosur.SetActive(true);

                 break;

         case "btn_video":

         btn_1.SetActive(true);

         btn_2.SetActive(false);

         sc_video.SetActive(true);

         sc_brosur.SetActive(false);

                 break;

     }

}

public void OnButtonReleased(VirtualButtonBehaviour vb) {

     Debug.Log("Button released!");

}

}

Creating 2 Virtual Button in 1 scene

September 28, 2021 - 8:16am #3

i'm using vuforia v9

Creating 2 Virtual Button in 1 scene

September 28, 2021 - 7:03am #2

Are you using VE v9.x or 10.x?

 

Kind regards,

Patrick Scheper

Technical Community Manager

Topic locked