Unity +HTC VIVE 虛擬現實開發— 手柄震動
阿新 • • 發佈:2019-01-09
廢話少說,直接上程式碼。
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)即可震動。