Unity Version : 2021.3.5f1
XR Interaction Toolkit : 2.2.0
XR Plugin Management : 4.3.1
Meta Quest 1
Hand.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
public class Hand : MonoBehaviour
{
public InputDeviceCharacteristics targetDeiveCharacteristics;
public InputDevice targetDevice;
[SerializeField]
private Animator handAnimator;
private void Start()
{
InitializeHand();
}
private void InitializeHand()
{
List<InputDevice> devices = new ();
InputDevices.GetDevicesWithCharacteristics(targetDeiveCharacteristics, devices);
if (devices.Count > 0) {
targetDevice = devices[0];
handAnimator = this.gameObject.GetComponent<Animator>();
}
}
private void Update()
{
if (!targetDevice.isValid) InitializeHand();
else UpdateHand();
}
private void UpdateHand()
{
if (targetDevice.TryGetFeatureValue(CommonUsages.trigger, out float triggerValue)) {
handAnimator.SetFloat("Trigger", triggerValue);
}
else {
handAnimator.SetFloat("Trigger", 0);
}
if (targetDevice.TryGetFeatureValue(CommonUsages.grip, out float gripValue))
{
handAnimator.SetFloat("Grip", gripValue);
}
else
{
handAnimator.SetFloat("Grip", 0);
}
}
}
https://www.youtube.com/watch?v=qQqNQ4y-cU8 <- 참고 자료