Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GrabManager : MonoBehaviour
  6. {
  7. public Transform tr;
  8. public Transform grabObject;
  9.  
  10. private bool isTouched = false;
  11. private bool isGrabbed = false;
  12.  
  13.  
  14.  
  15. // Start is called before the first frame updatec
  16. void Start()
  17. {
  18. tr = GetComponent<Transform>();
  19. }
  20.  
  21. void Update()
  22. {
  23. //잡는 동작
  24. if (isTouched && OVRInput.GetDown(OVRInput.Button.SecondaryHandTrigger))
  25. {
  26. grabObject.SetParent(tr);
  27. grabObject.GetComponent<Rigidbody>().isKinematic = true;
  28. isGrabbed = true;
  29. }
  30.  
  31. if (isGrabbed && OVRInput.GetUp(OVRInput.Button.SecondaryHandTrigger))
  32. {
  33. grabObject.SetParent(null);
  34. Vector3 _velocity = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch);
  35. grabObject.GetComponent<Rigidbody>().velocity = _velocity;
  36. grabObject.GetComponent<Rigidbody>().isKinematic = false;
  37. isGrabbed = false;
  38. isTouched = false;
  39. grabObject = null;
  40. }
  41.  
  42. if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger))
  43. {
  44. OVRInput.SetControllerVibration(0.5f, 0.5f, OVRInput.Controller.RTouch);
  45. }
  46. }
  47.  
  48. void OnTriggerEnter(Collider coll)
  49. {
  50. if (coll.gameObject.layer == 8)
  51. {
  52. grabObject = coll.transform;
  53. isTouched = true;
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement