2025-02-04 09:09:45 +08:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
|
|
|
2025-02-07 01:45:34 +08:00
|
|
|
public class RubbishBin : MonoBehaviour
|
2025-02-04 09:09:45 +08:00
|
|
|
{
|
2025-02-07 01:45:34 +08:00
|
|
|
private UnityEngine.XR.Interaction.Toolkit.Interactors.XRSocketInteractor socket;
|
2025-02-04 09:09:45 +08:00
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
2025-02-07 01:45:34 +08:00
|
|
|
socket = GetComponent<UnityEngine.XR.Interaction.Toolkit.Interactors.XRSocketInteractor>();
|
|
|
|
|
|
|
|
if (socket == null)
|
|
|
|
{
|
|
|
|
Debug.LogError("XRSocketInteractor component is missing from the rubbish bin!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
socket.selectEntered.AddListener(OnTrashPlaced);
|
2025-02-04 09:09:45 +08:00
|
|
|
}
|
|
|
|
|
2025-02-07 01:45:34 +08:00
|
|
|
private void OnTrashPlaced(SelectEnterEventArgs args)
|
2025-02-04 09:09:45 +08:00
|
|
|
{
|
2025-02-07 01:45:34 +08:00
|
|
|
UnityEngine.XR.Interaction.Toolkit.Interactables.XRBaseInteractable trash = (UnityEngine.XR.Interaction.Toolkit.Interactables.XRBaseInteractable)args.interactableObject;
|
|
|
|
|
|
|
|
if (trash != null)
|
2025-02-04 09:09:45 +08:00
|
|
|
{
|
2025-02-07 01:45:34 +08:00
|
|
|
Debug.Log($"{trash.gameObject.name} was placed in the rubbish bin and destroyed.");
|
|
|
|
Destroy(trash.gameObject);
|
2025-02-04 09:09:45 +08:00
|
|
|
|
2025-02-07 01:45:34 +08:00
|
|
|
// Add haptic feedback if using a VR controller
|
|
|
|
if (args.interactorObject is UnityEngine.XR.Interaction.Toolkit.Interactors.XRBaseInputInteractor controller)
|
2025-02-04 09:09:45 +08:00
|
|
|
{
|
2025-02-07 01:45:34 +08:00
|
|
|
controller.SendHapticImpulse(0.7f, 0.2f);
|
2025-02-04 09:09:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
2025-02-07 01:45:34 +08:00
|
|
|
if (socket != null)
|
|
|
|
{
|
|
|
|
socket.selectEntered.RemoveListener(OnTrashPlaced);
|
|
|
|
}
|
2025-02-04 09:09:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|