Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5.  
  6. public class GrabEvents : MonoBehaviour
  7. {
  8. private OVRGrabbable grabbable;
  9.  
  10. public UnityEvent StartGrab;
  11. public UnityEvent EndGrab;
  12. public UnityEvent WhileGrabbed;
  13.  
  14. private bool _grabNotified;
  15. private bool _releaseNotified;
  16.  
  17.  
  18. void Start()
  19. {
  20. grabbable = gameObject.GetComponent<OVRGrabbable>();
  21. }
  22.  
  23. void Update()
  24. {
  25. if (grabbable.isGrabbed)
  26. {
  27. WhileGrabbed.Invoke();
  28. }
  29.  
  30. if (grabbable.isGrabbed && !_grabNotified)
  31. {
  32. StartGrab.Invoke();
  33. _grabNotified = true;
  34. _releaseNotified = false;
  35. }
  36.  
  37. if (!grabbable.isGrabbed && !_releaseNotified)
  38. {
  39. EndGrab.Invoke();
  40. _grabNotified = false;
  41. _releaseNotified = true;
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement