Guest User

ControllerManager.cs

a guest
Oct 2nd, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ControllerManager : MonoBehaviour {
  5.  
  6.     public Rigidbody BulletPrefab;
  7.     public Transform BarrelEnd;
  8.     public float MyForce;
  9.     public float timer;
  10.     public GameObject PlayerBullet;
  11.     Animation otherAnimator;
  12.  
  13.     private Valve.VR.EVRButtonId triggerButton = Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger;
  14.     private SteamVR_TrackedObject trackedObject;
  15.     private SteamVR_Controller.Device device;
  16.  
  17.     void Start () {
  18.         trackedObject = GetComponent<SteamVR_TrackedObject> ();
  19.         timer = 0;
  20.     }
  21.  
  22.     void Update () {
  23.         timer += Time.deltaTime;
  24.  
  25.         device = SteamVR_Controller.Input ((int)trackedObject.index);
  26.         if(device.GetPressDown(triggerButton))
  27.         {
  28.             if (timer > 2.0f) {
  29.                 device.TriggerHapticPulse (700);
  30.                 otherAnimator = PlayerBullet.GetComponent<Animation> ();
  31.                 Rigidbody bulletInstance;
  32.                 bulletInstance = Instantiate (BulletPrefab, BarrelEnd.position, BarrelEnd.rotation) as Rigidbody;
  33.                 bulletInstance.AddForce (BarrelEnd.forward * MyForce);
  34.                 timer = 0;
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment