This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AW_2025/Assets/Scripts/SJM/Hand_Ray_OnOff.cs
2025-02-24 15:18:12 +09:00

71 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
//using UnityEditor.Animations;
using UnityEngine;
using UnityEngine.InputSystem.XR;
using UnityEngine.XR;
using UnityEngine.XR.Interaction.Toolkit;
using XRController = UnityEngine.XR.Interaction.Toolkit.XRController;
public class Hand_Ray_OnOff : MonoBehaviour
{
private Player player;
public GameObject ray;
[SerializeField]
public XRNode xrNode = XRNode.RightHand;
private InputDevice device;
private List<InputDevice> devices = new List<InputDevice>();
void Start()
{
player = FindObjectOfType<Player>();
ray.SetActive(false);
}
void GetDevice()
{
InputDevices.GetDevicesAtXRNode(xrNode, devices);
device = devices.FirstOrDefault();
}
private void OnEnable()
{
if (!device.isValid)
{
GetDevice();
}
}
void Update()
{
if (!device.isValid)
{
GetDevice();
}
if (!player.isDummy)
{
bool trigger = false;
if (device.TryGetFeatureValue(CommonUsages.triggerButton, out trigger) && trigger)
{
ray.SetActive(true);
player.Hand_Ray_Send("On");
}
else
{
ray.SetActive(false);
player.Hand_Ray_Send("Off");
}
}
}
public void DummyOnOff(bool o)
{
ray.SetActive(o);
}
}