60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.XR;
|
||
|
||
public class HandTakeObj : MonoBehaviour
|
||
{
|
||
bool isEnterObj;
|
||
Transform goodTran;
|
||
public XRNode xrNode = XRNode.LeftHand;
|
||
public Transform goodParent;
|
||
Good good;
|
||
|
||
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;
|
||
}
|
||
}
|
||
}
|