Created
August 8, 2019 12:38
-
-
Save andybak/55dffaaebad7fbed3efca0439487341b 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; | |
using UnityEngine.Events; | |
public class GrabEvents : MonoBehaviour | |
{ | |
private OVRGrabbable grabbable; | |
public UnityEvent StartGrab; | |
public UnityEvent EndGrab; | |
public UnityEvent WhileGrabbed; | |
private bool _grabNotified; | |
private bool _releaseNotified; | |
void Start() | |
{ | |
grabbable = gameObject.GetComponent<OVRGrabbable>(); | |
} | |
void Update() | |
{ | |
if (grabbable.isGrabbed) | |
{ | |
WhileGrabbed.Invoke(); | |
} | |
if (grabbable.isGrabbed && !_grabNotified) | |
{ | |
StartGrab.Invoke(); | |
_grabNotified = true; | |
_releaseNotified = false; | |
} | |
if (!grabbable.isGrabbed && !_releaseNotified) | |
{ | |
EndGrab.Invoke(); | |
_grabNotified = false; | |
_releaseNotified = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment