How to Make One Virtual Button Work at a Time?

Hi! I am currently working on an assignment and would like to implement multiple virtual buttons, however, I want to make sure that only one virtual button could be active at a time. I plan to have multiple models be attached to their own virtual button, I just don't want multiple virtual buttons be sensed at once and have more than one model on screen at a time. For example, I have a coffee cup appear when one virtual button is pressed and have a tea cup appear when a different button is pressed. They cannot appear at the same time though. How do I do that?

Currently, I have one model set (coffee cup) to appear when the virtual button is pressed. This is the code I did for the virtual button.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class MidtermVirtualButton : MonoBehaviour
{

public GameObject CoffeeCup;
public VirtualButtonBehaviour Vb;

// Start is called before the first frame update
void Start()
{
Vb.RegisterOnButtonPressed(OnButtonPressed);
Vb.RegisterOnButtonReleased(OnButtonReleased);

CoffeeCup.SetActive(false);
}

public void OnButtonPressed(VirtualButtonBehaviour vb)
{
CoffeeCup.SetActive(true);
}

public void OnButtonReleased(VirtualButtonBehaviour vb)
{
CoffeeCup.SetActive(false);
}
}

And how you gonna to press another button to show different game object, when user can't see another button?

In such situations, you can use ToggleGroup with a set of Toggles.

I have such video demo of AR Gallery that shows ToggleGroup exerience below.

P.S. Please use "Insert Code" button to insert code properly instead of pasting it as text.

https://www.youtube.com/watch?v=7WJPh1KLwmM

The idea is to use a menu as an image target. Over each item on the menu, there’s a virtual button that will display a model and a UI button when the virtual button is pressed. I want to make sure that as someone’s hand is going across the menu to pick the one item, other buttons aren’t being sensed. Another issue that recently came up was the first item and virtual button I implemented remain stuck to the image target while the second item doesn’t show up at all.


Oh, just realized that you are talking about Vuforia...

Why? If the hand will cover several buttons at a time?

Unfortunately, there is a 404 error of Virtual Button in Vuforia docs. Does it have the same field as "interactable" on Button from Unity UI?

I'm not completely clear on the details of your implementation, but broadly speaking you can ensure that the tea cup and coffee cup do not appear at the same time by disabling the tea cup whenever you enable the coffee cup, and vice versa. To use the class you provided as an example:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;

public class MidtermVirtualButton : MonoBehaviour {

   public GameObject CoffeeCup;
   public GameObject TeaCup;
   public VirtualButtonBehaviour Vb;

    // Start is called before the first frame update
   void Start() {
      Vb.RegisterOnButtonPressed(OnButtonPressed);
      Vb.RegisterOnButtonReleased(OnButtonReleased);

      CoffeeCup.SetActive(false);
   }

   public void OnButtonPressed(VirtualButtonBehaviour vb) {
      CoffeeCup.SetActive(true);
      TeaCup.SetActive(false);
   }

   public void OnButtonReleased(VirtualButtonBehaviour vb) {
      CoffeeCup.SetActive(false);
      TeaCup.SetActive(true);
   }
}