using System; using System.Collections; using System.Collections.Generic; using Unity.XR.PXR; using UnityEngine; using UnityEngine.XR; public class HandTakeObj : MonoBehaviour { bool isEnterObj; Transform goodTran; //public PXR_Input.Controller hand; XRNode xrNode; public Transform goodParent; Good good; void Start() { switch (hand) { case PXR_Input.Controller.LeftController: xrNode = XRNode.LeftHand; break; case PXR_Input.Controller.RightController: xrNode = XRNode.RightHand; break; default: break; } } void Update() { if (isEnterObj) { if (InputDevices.GetDeviceAtXRNode(xrNode).TryGetFeatureValue(CommonUsages.trigger, out float triggerValue)) { if (triggerValue > 0.6f) { goodTran.SetParent(transform); good.IsJiaohu = true; } else { goodTran.SetParent(goodParent); good.IsJiaohu = false; good.sendGoodPos(); } } } } private void OnTriggerEnter(Collider other) { if (goodTran == null && other.gameObject.layer == 6) { // ͨ�����ϲ��Ҹ����壬ֱ��û�и�����Ϊֹ����ȡ���ϲ㸸���� goodTran = other.transform; while (goodTran.parent != goodParent) { goodTran = goodTran.parent; } good = goodTran.GetComponent(); isEnterObj = true; } } private void OnTriggerExit(Collider other) { if (goodTran != null && other.gameObject.layer == 6) { goodTran = null; isEnterObj = false; } } }