我正试着用SteamVR和VRTK制作一把枪,但我不知道如何正确地获得控制器输入。当我使用SteamVR跟踪控制器脚本时,我得到一个IsMatrixValid错误,它弄乱了我的头盔显示器。我目前正在尝试使用VRTK控制器事件方法,但即使我正确地跟踪了视频,它仍然作为null返回。
Screenshot of script location in project
问题视频:https://www.youtube.com/watch?v=escwjnHFce0 (14:17)
有问题的脚本:
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");
}
}
}发布于 2017-10-25 02:51:07
从你的脚本中删除这3行代码,它就可以工作了
void TriggerPressed(object sender, VRTK.ControllerInteractionEventArgs e)
{
ShootWeapon();
}https://stackoverflow.com/questions/46250481
复制相似问题