Created
February 17, 2017 14:26
-
-
Save kazumalab/749968a5a9a41debf4007402fbbf46e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Gun : MonoBehaviour { | |
public GameObject bullet; | |
public AudioSource audio_source; | |
private Transform point; | |
private bool ishold = false; | |
private OVRHand holdHand; | |
private OVRHaptics.OVRHapticsChannel hapticsChannel; | |
private OVRHapticsClip hapticsClip; | |
private OVRInput.RawButton whichFinger; | |
// Use this for initialization | |
void Start () { | |
point = transform.FindChild ("BulletPoint"); | |
hapticsClip = new OVRHapticsClip (audio_source.clip); | |
} | |
// Update is called once per frame | |
void Update () { | |
if (!ishold) { | |
if (transform.parent != null) { | |
getHand (); | |
} | |
} | |
if (ishold) { | |
if (OVRInput.GetDown (whichFinger)) { | |
hapticsChannel.Mix (hapticsClip); | |
GameObject b = Instantiate (bullet, point.transform.position, bullet.transform.rotation); | |
audio_source.Play (); | |
b.transform.LookAt (transform.forward * -100f); | |
} | |
if (transform.parent == null) { | |
Release (); | |
} | |
} | |
} | |
private void getHand () { | |
holdHand = transform.GetComponentInParent<OVRHand> (); | |
if (holdHand.whichController == OVRInput.Controller.LTouch) { | |
hapticsChannel = OVRHaptics.LeftChannel; | |
whichFinger = OVRInput.RawButton.LIndexTrigger; | |
} | |
if (holdHand.whichController == OVRInput.Controller.RTouch) { | |
hapticsChannel = OVRHaptics.RightChannel; | |
whichFinger = OVRInput.RawButton.RIndexTrigger; | |
} | |
ishold = true; | |
} | |
private void Release () { | |
ishold = false; | |
holdHand = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment