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!
Hi ,can i get code for 3 multiple virtual buttons using vuforia
when i touch one button then it should get the information of the first button ,then if we remove then it should not show the information of 1 st button ,then if we touch the 2nd button that information and soo on ....
can any one send me the code for this ?? please