首页 > 解决方案 > 在下面的代码中解释 GvrPointerInputModule.pointer

问题描述

我在我的脚本中添加了以下代码行,以启用对在 google daydream 中播放的统一 VR 游戏的控制器支持。如果没有此代码,控制器将不会显示在游戏的最终版本中

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
    }
}

有人可以解释一下为什么我需要在游戏过程中启用控制器主和控制器,它们在层次结构中没有被禁用。并解释第3行代码

标签: c#unity3ddaydream

解决方案


controllerMaincontrollerPointer变量分别只是对GvrControllerMainGvrControllerPointer GameObject预制件的引用。GvrControllerPointer 提供用于光线投射的内置激光指示器。需要 GvrControllerMain 才能使用 Daydream 控制器。

呼叫controllerMain.SetActive(true)将激活GvrControllerMain。当你调用SetActive它时,同样的事情也适用于 GvrControllerPointer。运行 Daydream 时,这两个都应该被激活。这就是为什么在运行时激活和停用它们的原因,因为那时您可以确定这是否是白日梦设备。

GvrPointerInputModule.Pointer用于设置指针类型。有一个GvrLaserPointerGvrReticlePointer。在您的示例中,您告诉 Gvr 模块使用GvrLaserPointer并且是一种激光视觉,当光标不在他们的视野中时,它可以帮助用户定位光标。


推荐阅读