Files
PrinceOfGlory/Assets/代码/Pico交互/HandTakeObj.cs
Sora丶kong 82130f6146 上传修改
2026-03-03 10:57:00 +08:00

77 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
{
// ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD>ϲ<EFBFBD><CFB2>Ҹ<EFBFBD><D2B8><EFBFBD><EFBFBD>壬ֱ<E5A3AC><D6B1>û<EFBFBD>и<EFBFBD><D0B8><EFBFBD><EFBFBD><EFBFBD>Ϊֹ<CEAA><D6B9><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ϲ<CFB2><E3B8B8><EFBFBD><EFBFBD>
goodTran = other.transform;
while (goodTran.parent != goodParent)
{
goodTran = goodTran.parent;
}
good = goodTran.GetComponent<Good>();
isEnterObj = true;
}
}
private void OnTriggerExit(Collider other)
{
if (goodTran != null && other.gameObject.layer == 6)
{
goodTran = null;
isEnterObj = false;
}
}
}