4
votes

I'm trying to detect cardboard button click with Cardboard Unity SDK.

I'm using this

Google VR SDK for Unity v1.40 (April 2017), right now it's the latest

I'm using Unity 5.6.0f3, this also seems to be latest currently.

I'm not able to detect the button click using

GvrViewer.Instance.Triggered

Unity UI events are working as expected (Buttons and all), however I need to perform some action without using UI, like jumping on click of the button in the cardboard.

In the latest release Google VR SDK says that it has removed support for the magnetic button. However I'm not using the magnetic button. Mine has button which works with touch screen. (Version released after Google IO 2015)

This is the cardboard that I'm using enter image description here

I just can't figure out how to detect the normal button press.

Any information is appreciated.

*Edit *

Following is the line from GvrViewer where Triggered is populated.

  private void DispatchEvents() {
      // Update flags first by copying from device and other inputs.
    Triggered = Input.GetMouseButtonDown(0);
#if UNITY_HAS_GOOGLEVR && (UNITY_ANDROID || UNITY_EDITOR)
    Triggered |= GvrController.ClickButtonDown;
#endif  // UNITY_HAS_GOOGLEVR && (UNITY_ANDROID || UNITY_EDITOR)

I have checked it in various combinations on the phone it doesn't work.

1
In the cardboard button there is a magnet, and when it's pressed the phone recognizes it as a screen tap. In other words, in Unity it should be a left mouse button click.Hristo
Magnet button was different, it used to interact with the magnetometer of phone. It was used in the first version of the cardboard, in the second version it uses screen touch. You are right that screen touch should be left click, that's how the value of Triggered variable is populated for the affected frame. It's not working though, I have added relevant code and link.11thdimension
Have you tried this or this?Hristo
Both of those are for magnet buttons and second one seems to have a copyright notice. I ended up using touch events, see my answer.11thdimension

1 Answers

6
votes

Since I couldn't get the Google VR way of detecting the button press working (which is GvrViewer.Instance.Triggered) I ended up using touch events provided by Unity on touch devices.

Right now my condition looks like following

Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began