private void Start() { cam = Camera.main; camTransform = cam.transform; grabPosition = GetComponentInChildren <GrabPosition>(); grabTransformPosition = grabPosition.transform; grabTransformPosition.SetParent(camTransform); Cursor.lockState = CursorLockMode.Locked; }
void Update() { if (candidateHand && candidateHand.gesture == Hand.Gesture.GRAB && !candidateHand.GetComponentInChildren <Grabbable>()) { Rigidbody rigidbody = GetComponent <Rigidbody>(); this.transform.parent = candidateHand.transform; rigidbody.isKinematic = true; GrabPosition grabPosition = candidateHand.GetComponentInChildren <GrabPosition>(); if (grabPosition != null) { this.transform.localPosition = grabPosition.offset; } else { this.transform.localPosition = new Vector3(0f, 0f, 0f); } candidateHand = null; } }