wirm/Game/Assets/Scripts/socket.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2025-02-04 09:09:45 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.XR.Interaction.Toolkit.Interactables;
using UnityEngine.XR.Interaction.Toolkit.Interactors;
2025-02-06 23:12:45 +08:00
public class Socket : MonoBehaviour
2025-02-04 09:09:45 +08:00
{
private XRSocketInteractor socket;
private void Start()
{
socket = GetComponent<XRSocketInteractor>();
socket.selectEntered.AddListener(OnObjectPlaced);
}
private void OnObjectPlaced(SelectEnterEventArgs args)
{
XRBaseInteractable interactable = (XRBaseInteractable)args.interactableObject;
if (interactable != null)
{
Debug.Log($"Object {interactable.gameObject.name} placed in socket!");
// Example: Add haptic feedback to controllers
if (args.interactorObject is XRBaseInputInteractor controller)
{
controller.SendHapticImpulse(0.5f, 0.2f);
}
}
}
private void OnDestroy()
{
socket.selectEntered.RemoveListener(OnObjectPlaced);
}
}