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
Frontec/Assets/Scripts/SJM/XR_Ray_Controller.cs
jmaniuvc 2936c48466 Frontec
2025-02-24 12:12:52 +09:00

74 lines
1.6 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 XR_Ray_Controller : MonoBehaviour
{
public XRController controller;
public XRInteractorLineVisual ray;
//public GameObject reticle;
[SerializeField]
public XRNode xrNode = XRNode.LeftHand;
private InputDevice device;
private List<InputDevice> devices = new List<InputDevice>();
void Start()
{
ray = GetComponent<XRInteractorLineVisual>();
ray.enabled = false;
//reticle = GameObject.FindWithTag("Reticle");
//reticle.SetActive(false);
}
void GetDevice()
{
InputDevices.GetDevicesAtXRNode(xrNode, devices);
device = devices.FirstOrDefault();
}
private void OnEnable()
{
if (!device.isValid)
{
GetDevice();
}
}
void Update()
{
if (!device.isValid)
{
GetDevice();
}
bool trigger = false;
if (device.TryGetFeatureValue(CommonUsages.triggerButton, out trigger) && trigger)
{
ray.enabled = true;
}
else
{
ray.enabled = false;
/*
reticle = GameObject.FindWithTag("Reticle");
if (reticle != null)
{
reticle.SetActive(false);
}
*/
}
}
}