Hi!
I'm a newbie to scripting, familiar with some javascripting only and I'm still learning.
I've followed the steps in this thread using the below code saving it as VirtualButtonEventHandler. I've attached the script to the image target. I've named both game objects cube and sphere, as well as the buttons cube_button and sphere_button. When I build and run the app the sphere and cube appear but the virtual buttons have no effect.
These errors also pop up:
------
Duplicate virtual buttons with name 'undefined' detected in Image Target 'stones'.
UnityEngine.Debug:LogError(Object)
VirtualButtonEditor:DetectDuplicates(ImageTargetBehaviour) (at Assets/Editor/QCAR/Scripts/VirtualButtonEditor.cs:294)
VirtualButtonEditor:Validate() (at Assets/Editor/QCAR/Scripts/VirtualButtonEditor.cs:25)
SceneManager:EditorUpdate() (at Assets/Editor/QCAR/Scripts/SceneManager.cs:206)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
Assets/Qualcomm Augmented Reality/Scripts/Internal/BGRenderingBehaviour.cs(40,31): warning CS0618: `UnityEngine.GameObject.active' is obsolete: `GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.'
Assets/Qualcomm Augmented Reality/Scripts/Internal/BGRenderingBehaviour.cs(41,31): warning CS0618: `UnityEngine.GameObject.SetActiveRecursively(bool)' is obsolete: `gameObject.SetActiveRecursively() is obsolete. Use GameObject.SetActive(), which is now inherited by children.'
-----
Help/instructions would be incredibly appreciated. I'm using this for a graduate reserach project. I can send someone the file if needed.
using UnityEngine;
using System.Collections;
public class ButtonEventHandler : MonoBehaviour, IVirtualButtonEventHandler {
public GameObject cube;
public GameObject sphere;
void Start()
{
// Register with the virtual buttons TrackableBehaviour
VirtualButtonBehaviour[] vbs = GetComponentsInChildren<VirtualButtonBehaviour>();
for (int i = 0; i < vbs.Length; ++i)
{
vbs[i].RegisterEventHandler(this);
}
cube = transform.FindChild("cube").gameObject;
sphere = transform.FindChild("sphere").gameObject;
sphere.renderer.enabled = false;
}
// Called when the virtual button has just been pressed:
public void OnButtonPressed(VirtualButtonBehaviour vb)
{
Debug.Log("OnButtonPressed");
switch (vb.VirtualButtonName)
{
case "cube_button":
Display( cube );
Hide( sphere );
break;
case "sphere_button":
Display( sphere );
Hide( cube );
break;
}
}
public void OnButtonReleased(VirtualButtonBehaviour vb)
{
Debug.Log("OnButtonReleased");
switch (vb.VirtualButtonName)
{
case "cube_button":
break;
case "sphere_button":
break;
}
}
void Display( GameObject obj){
Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();
// Enable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = true;
}
}
void Hide( GameObject obj ){
Renderer[] rendererComponents = obj.GetComponentsInChildren<Renderer>();
// Disable rendering:
foreach (Renderer component in rendererComponents)
{
component.enabled = false;
}
}
}
Hello I have the same problem, look forward to your answer, how do I change the behavior of DefaultTrackableEventHandler,thanks very much