I am adding the following line of code in my script to enable controller support for unity VR game which is being played in google daydream. Without this code, the controller is not showing in the final build of the game
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class InputManager : MonoBehaviour
{
public GameObject controllerMain;
public GameObject controllerPointer;
private void Start()
{
controllerMain.SetActive(true);
controllerPointer.SetActive(true);
GvrPointerInputModule.Pointer =
controllerPointer.GetComponentInChildren<GvrLaserPointer>();//3
}
}
Can someone explain me why I need to enable controllermain and controller during gamelay they are not disabled in the hierarchy. And explain the 3rd line of code
The controllerMain
and controllerPointer
variables are just references to GvrControllerMain and GvrControllerPointer GameObject prefabs respectively. GvrControllerPointer provides built-in laser pointer used for raycasting. GvrControllerMain is required to use the Daydream controller.
Calling controllerMain.SetActive(true)
will activate GvrControllerMain
. The-same thing applies to GvrControllerPointer when you call call SetActive
on it. Both of these should be activated when running daydream. This is why the activating and de-activating of them happens during run-time because that's when you can determine if this is a daydream device or not.
GvrPointerInputModule.Pointer
is used to set the pointer type. There is a GvrLaserPointer
and GvrReticlePointer
. In your example, you were telling the Gvr module to use GvrLaserPointer
and is a laser visual that helps users locate their cursor when its not directly in their field of view.