Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GrabManager : MonoBehaviour
- {
- public Transform tr;
- public Transform grabObject;
- private bool isTouched = false;
- private bool isGrabbed = false;
- // Start is called before the first frame updatec
- void Start()
- {
- tr = GetComponent<Transform>();
- }
- void Update()
- {
- //잡는 동작
- if (isTouched && OVRInput.GetDown(OVRInput.Button.SecondaryHandTrigger))
- {
- grabObject.SetParent(tr);
- grabObject.GetComponent<Rigidbody>().isKinematic = true;
- isGrabbed = true;
- }
- if (isGrabbed && OVRInput.GetUp(OVRInput.Button.SecondaryHandTrigger))
- {
- grabObject.SetParent(null);
- Vector3 _velocity = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch);
- grabObject.GetComponent<Rigidbody>().velocity = _velocity;
- grabObject.GetComponent<Rigidbody>().isKinematic = false;
- isGrabbed = false;
- isTouched = false;
- grabObject = null;
- }
- if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger))
- {
- OVRInput.SetControllerVibration(0.5f, 0.5f, OVRInput.Controller.RTouch);
- }
- }
- void OnTriggerEnter(Collider coll)
- {
- if (coll.gameObject.layer == 8)
- {
- grabObject = coll.transform;
- isTouched = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement