Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

GoogleVR SDK: Event Trigger not working correctly? (Gazing at objects) [Android]

Discussion in 'VR' started by vanhauttebram, Nov 16, 2018.

  1. vanhauttebram

    vanhauttebram

    Joined:
    Nov 16, 2018
    Posts:
    10
    Hello all, and thank you for reading this.

    Recently I started experiencing with VR and I started out with the GoogleVR SDK (GoogleVR_for_Unity_1.170.0).

    What I wanted to do was setting a 3D-cube in front of my Main Camera. When focussing the middlepoint of the screen (so actually the focus of the eyes) on the cube, it should move towards me.

    So what have I done, and what does not work?
    First of all, I adjusted the build settings to an Android application and adjusted the player settings (VR enabled with cardboard and filled in the settings). So Company name, product name, minimum Android version 4.4.

    I set up a new project, and made the cube. I set up the box collider to the same shape and dimensions of the cube. My main camera is looking to the cube.

    I added a custom script to the cube, with a public function MoveCube(), and if that function get's called, the cube should move. I tested this with the "OnMouseOver()" premade function, and the cube moves when my real mouse hovers over it (so the script should work).
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class MoveCube : MonoBehaviour
    6. {
    7.     public Vector3 lastPosition;
    8.  
    9.     // Use this for initialization
    10.     void Start()
    11.     {
    12.         lastPosition = transform.position;
    13.     }
    14.  
    15.     private void OnMouseOver()
    16.     {
    17.         if (lastPosition.z != -8)
    18.         {
    19.             lastPosition = new Vector3(lastPosition.x, lastPosition.y, lastPosition.z - 0.01f);
    20.             transform.position = lastPosition;
    21.         }
    22.     }
    23.  
    24.     public void LookAtCube()
    25.     {
    26.         if (lastPosition.z != -8)
    27.         {
    28.             lastPosition = new Vector3(lastPosition.x, lastPosition.y, lastPosition.z - 0.5f);
    29.             transform.position = lastPosition;
    30.         }
    31.     }
    32. }
    As you can see, my function is called LookAtCube().

    Then I added the GVREditorEmulator to the base level of the project, so that we can test it as it was on an Android phone. I also added the GvrEventSystem. On top of that, I added the GvrPointerPhysicsRaycaster onto the Main Camera and GvrEventSystem.
    I also added the GvrReticlePointer to the main camera so that we have a white dot in the center of our Game screen (so the focus point).

    What I then did was add an Event Trigger to the Cube, set it as Pointer Enter and selected my Cube + my custom function LookAtCube().

    Normally, when focussing on the Cube, it should now move toward me. It does not. It only moves towards me when my computer mouse is on the cube (again proven that it is a problem with the Event Trigger).

    I found many many guides using this method and it all worked fine. I copied some exactly but it was not working. Does anyone have any ideas on where to go with this, or what is going wrong?

    Thanks for the time!