首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >返回null的VRTK_ControllerEvents

返回null的VRTK_ControllerEvents
EN

Stack Overflow用户
提问于 2017-09-16 13:39:11
回答 1查看 268关注 0票数 0

我正试着用SteamVR和VRTK制作一把枪,但我不知道如何正确地获得控制器输入。当我使用SteamVR跟踪控制器脚本时,我得到一个IsMatrixValid错误,它弄乱了我的头盔显示器。我目前正在尝试使用VRTK控制器事件方法,但即使我正确地跟踪了视频,它仍然作为null返回。

Screenshot of script location in project

问题视频:https://www.youtube.com/watch?v=escwjnHFce0 (14:17)

有问题的脚本:

代码语言:javascript
复制
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EZEffects;
using VRTK;


public class GunBehavior : MonoBehaviour {

public VRTK_ControllerEvents controllerEvents;

private SteamVR_TrackedObject trackedObj;


public EffectTracer TracerEffect;
public Transform muzzleTransform;

// Use this for initialization
void Start () {
    Debug.Log(controllerEvents);
    if (controllerEvents)
    {
        Debug.Log("Hue22");
    }
    else
    {
        Debug.Log("work");
    }
}

// Update is called once per frame
void Update () {

    if (controllerEvents.triggerPressed)
    {
        ShootWeapon();
    }
}

void TriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e)
{
    ShootWeapon();
}

void ShootWeapon()
{
    RaycastHit hit = new RaycastHit();
    Ray ray = new Ray(muzzleTransform.position, muzzleTransform.forward);

    TracerEffect.ShowTracerEffect(muzzleTransform.position, muzzleTransform.forward, 250f);

    if (Physics.Raycast(ray, out hit, 5000f))
    {
        Debug.Log("Hueheuhue");
    }
}
}
EN

回答 1

Stack Overflow用户

发布于 2017-10-25 02:51:07

从你的脚本中删除这3行代码,它就可以工作了

代码语言:javascript
复制
void TriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e)
{
    ShootWeapon();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46250481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档