Skip to content

Instantly share code, notes, and snippets.

@andybak
Created August 8, 2019 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andybak/55dffaaebad7fbed3efca0439487341b to your computer and use it in GitHub Desktop.
Save andybak/55dffaaebad7fbed3efca0439487341b to your computer and use it in GitHub Desktop.
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