Log in or register to post comments

Virtual Buttons

July 11, 2017 - 9:02am #1

Hello Community,

 

im desperate and thats why im posting here. I followed several tutorials but i didn't get any solution and thats why im here now

 

I use the Vuforia Framework and Im trying to implement a virtual button to rotate my 3D Model.

After putting the Virtual Button, which is a child of my image target, above the image target, i don't get "button pressed" in the console, when i "hit" the button

in play mode. I renamed the virtual button to RotateZombieButton. 

 

Is this enough information or do i need to provide more information?

 

thanks in advance!

 

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


public class VBScript : MonoBehaviour, IVirtualButtonEventHandler {

private GameObject VBButtonObject;

void Start () {

  VBButtonObject = GameObject.Find ("RotateZombieButton");
  VBButtonObject.GetComponent<VirtualButtonAbstractBehaviour> ().RegisterEventHandler (this);
}

// Update is called once per frame
public void OnButtonPressed (VirtualButtonAbstractBehaviour vb) {
  Debug.Log ("Button pressed");
}



public void OnButtonReleased (VirtualButtonAbstractBehaviour vb) {
  Debug.Log ("Button released");
}
}

 

 

Virtual Buttons

July 13, 2017 - 10:22am #4

Looks like your zombie object is null when you press the button. Make sure it exists in the scene and is being assigned to your variable properly.

Thanks,

-Vuforia Support

Virtual Buttons

July 13, 2017 - 1:51am #3

 Type your code in the box. To create a new line within the box use SHIFT + ENTER. Hello,

 

this doesn't help me!

 

Please is there somebody to help me i google all day every day to fix this but no help

 

So this is my code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using Vuforia;

public class vbScipt : MonoBehaviour, IVirtualButtonEventHandler {

private GameObject vbButtonObject;

private GameObject zombie;



}

// Use this for initialization

void Start () {



  vbButtonObject = GameObject.Find ("actionButton");

  zombie = GameObject.Find ("zombie");

  vbButtonObject.GetComponent<VirtualButtonAbstractBehaviour> ().RegisterEventHandler (this);

}



public void OnButtonPressed (VirtualButtonAbstractBehaviour vb){

  Debug.Log ("Button Pressed");

zombie.transform.Rotate (0, 1000 * Time.deltaTime, 0);

}

public void OnButtonReleased (VirtualButtonAbstractBehaviour vb){

  Debug.Log ("Button Released");

  zombie.GetComponent<Animation> ().Stop ();

}

}

 

 

 

And i get this error: 

Exception in callback: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object

  at vbScipt.OnButtonPressed (Vuforia.VirtualButtonAbstractBehaviour vb) [0x00011] in /Users/denyscarlino/FutureDeck(T.V)/Assets/Scripts/vbScipt.cs:23

  at Vuforia.VirtualButtonAbstractBehaviour.OnTrackerUpdated (Boolean pressed) [0x00000] in <filename unknown>:0

  at Vuforia.StateManagerImpl.UpdateVirtualButtons (Int32 numVirtualButtons, IntPtr virtualButtonPtr) [0x00000] in <filename unknown>:0

  at Vuforia.VuforiaManagerImpl.UpdateTrackers (FrameState frameState) [0x00000] in <filename unknown>:0

  at Vuforia.VuforiaManagerImpl.Update (ScreenOrientation counterRotation, Boolean reapplyOldState) [0x00000] in <filename unknown>:0

  at Vuforia.VuforiaARController.UpdateStatePrivate (Boolean forceUpdate, Boolean reapplyOldState) [0x00000] in <filename unknown>:0

  at Vuforia.VuforiaARController.UpdateState (Boolean forceUpdate, Boolean reapplyOldState) [0x00000] in <filename unknown>:0

  at Vuforia.DigitalEyewearARController.Update () [0x00000] in <filename unknown>:0

  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)

  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d0] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222

  --- End of inner exception stack trace ---

  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000eb] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232

  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115

  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x000b9] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:443

  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00018] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/MulticastDelegate.cs:71

  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:415

  at Vuforia.DelegateHelper.InvokeDelegate (System.Delegate action, System.Object[] args) [0x00000] in <filename unknown>:0

UnityEngine.Debug:LogError(Object)

Vuforia.DelegateHelper:InvokeDelegate(Delegate, Object[])

Vuforia.DelegateHelper:InvokeWithExceptionHandling(Action)

Vuforia.VuforiaAbstractBehaviour:Update()

Virtual Buttons

July 11, 2017 - 10:07am #2

Hello denyscarlino,

The sample project contains a scene demonstrating the use of virtual buttons. You can get the sample on the Unity Asset Store or on our webpage: https://developer.vuforia.com/downloads/samples

Thanks,

-Vuforia Support

Log in or register to post comments