Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement