Unity +HTC VIVE 虚拟现实开发— 手柄震动

废话少说,直接上代码。this

using UnityEngine;
using System.Collections;

public class shoubingzhendong : MonoBehaviour {

    SteamVR_TrackedObject tracked;
    

	// Use this for initialization
	void Start () {

        tracked = GetComponent<SteamVR_TrackedObject>();
	}
	
	// Update is called once per frame
	void Update () {

        var device = SteamVR_Controller.Input((int)tracked.index);

        //手柄扳机键按下
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { 
        
            //震动
            device.TriggerHapticPulse(500);
        }
	
	}
}
只要将此脚本放置在手柄上,而后按下扳机键(Trigger)便可震动。