Log in or register to post comments

Multiple virtual button issue

April 25, 2012 - 9:19pm #1

Hi, I'm working on a project that requires multiple virtual buttons (5) to trigger animations. The animations are already rendered and imported, no issues, and I'm able to write code for a single button successfully, but when I write for multiples the buttons do nothing. I am working in Unity 3.5Of5 and the c# script is as follows:

using UnityEngine;
using System.Collections.Generic;

public class VirtualButtonEventHandler : MonoBehaviour,
IVirtualButtonEventHandler
{

public GameObject mBuilding_85;

public GameObject mB_jumpout;

public GameObject mKit_walk;

public GameObject mKit_idle;

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

mBuilding_85 = transform.FindChild("building_85").gameObject;

mB_jumpout = transform.FindChild("B_jumpout").gameObject;

mKit_walk = transform.FindChild("kit_walk").gameObject;

}

// Called when the virtual button has just been pressed:
public void OnButtonPressed(VirtualButtonBehaviour vb)
{
Debug.Log("OnButtonPressed");

if (!IsValid())
{
return;
}

// Select Case for handling each button
switch (vb.VirtualButtonName)
{
case "Page3Button":
mBuilding_85.animation.Play();
break;

case "ScreenButton":
mB_jumpout.animation.Play();
break;

case "AlexWalk":
mKit_walk.animation.Play();
break;

/*case "":
break; */
}

}

// Called when the virtual button has just been released:
public void OnButtonReleased(VirtualButtonBehaviour vb)
{
// OK, I'll mess around with this code later assuming you want on button released behaviour.

if (!IsValid())
{
return;
}

// Remove the material corresponding to this virtual button
// from the active material list:
switch (vb.VirtualButtonName)
{
case "AlexWalk":
mKit_idle = transform.FindChild("kit_idle").gameObject;
break;
}

/* Apply the next active material, or apply the default material:
if (mActiveMaterials.Count > 0)
mTeapot.renderer.material = mActiveMaterials[mActiveMaterials.Count - 1];
else
mTeapot.renderer.material = m_TeapotMaterials[4]; */
}

private bool IsValid()
{
// Check the materials and teapot have been set:
/* return m_TeapotMaterials != null &&
m_TeapotMaterials.Length == 5 &&
mTeapot != null;*/

return true;
}
}

Any suggestions would be most welcome. Thanks in advance!

Multiple virtual button issue

December 22, 2018 - 10:35am #8

Hi, I am working on a same problem as yours , it is an idea to work with multiple virtual buttons both directy seen to camera and touchable on the screen. 

In a case that I am interested in you can use your materials on the button more than once from one screen. 

public void OnButtonReleased(Open1)

{

open1 = transform.gameobject[activematerials];

}

 

You can use examples like this because the problem both you and me has experienced is because of two types of virtualbuttons. They are not working simultaneously but working with no error when you use them one by one.

Multiple virtual button issue

May 29, 2018 - 10:39am #7

Hi how do you guys manage to make a virtual button to trigger video? i am quite new to vuforia, so please help!!, or if someone manage to make it, can you share the script? Thankyousomuch

Multiple virtual button issue

March 8, 2017 - 11:16pm #6

Hey All, 



Currently, I am working on multiple videos with respective multiple virtual buttons playing concept. 



So far I have achieved everything perfectly. Now the problem arising is, while I am trying to interact with virtual buttons, it is playing only 1 video for all virtual buttons. 



PS: I have clearly added the paths (local prefabs). 



 

Multiple virtual button issue

November 7, 2016 - 12:20pm #5

The sample code from Vuforia has the tea pot example that take care of multiple buttons in one C# file called VuforiaButtonHandler.

https://developer.vuforia.com/downloads/samples

Multiple virtual button issue

November 7, 2013 - 8:06pm #4

finally i can solve my problem. Thank's for all of your responds.

Multiple virtual button issue

September 27, 2013 - 5:25am #3

Hai Brad, i'm the new one who use virtual button. i hope you can help me. I'm going to make multipple moving  virtual button.
I want to make a game like Ant Smasher, so i need my object and the virtual button moving on the schene.

But i got a problem in using the virtual button, can i ask u something?

Should i make a prefab of my object that i want to load, include the virtual button in it? Then i make each VirtualButtonEventHandler for every prefab that i make?

i'm so sorry, and thank's.

Re: Multiple virtual button issue

April 26, 2012 - 7:44pm #2

Solved it by writing separate VirtualButtonEventHandler scripts for each button on each image tracker. Still curious about the script for multiple buttons though.

Log in or register to post comments