按下触发器时未注册

时间:2018-12-12 17:20:43

标签: c# unity3d steamvr

我有一些代码,当按下右手控制器的触发器时,它会开枪,但是它似乎不起作用,我试图在实际的TriggerPressed部分中添加调试,并且当我在游戏中单击它时,它也不会显示在日志中,我只是不确定该问题是从哪里产生的,并且对于为什么它不起作用感到困惑。它也可以编译,因此任何指导都值得赞赏

编辑:不确定其重要性,但还是决定使用oculus rift控制器的

添加它。

这是(edit:UPDATED)代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EZEffects;

public class adamadam : MonoBehaviour
{

public SteamVR_TrackedController controllerRight;

private SteamVR_TrackedObject trackedObj;
private SteamVR_Controller.Device device;

private SteamVR_TrackedController controller;

public EffectTracer TracerEffect;
public Transform muzzleTransform;

// Use this for initialization
void Start()
{

 //  controller = controllerRight.GetComponent<SteamVR_TrackedController>();
        controller.TriggerClicked += TriggerPressed;
      //  trackedObj = controllerRight.GetComponent<SteamVR_TrackedObject>();
}

private void TriggerPressed(object sender, ClickedEventArgs e)
{
    Debug.Log("Clicked");
    ShootWeapon();
}


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

    device = SteamVR_Controller.Input((int)trackedObj.index);
    device.TriggerHapticPulse(750);
    TracerEffect.ShowTracerEffect(muzzleTransform.position, 
muzzleTransform.forward, 250f);

    if (Physics.Raycast(ray, out hit, 5000f))
    {
        if (hit.collider.attachedRigidbody)
        {
            Debug.Log("Hit" + hit.collider.gameObject.name);
        }
    }

}



}

0 个答案:

没有答案