using _PROJECT.NewHandPresence; using System.Collections.Generic; using UnityEngine; public enum GrabbingHand { Right, Left } public class DoorHandReplacer : MonoBehaviour { public GameObject LeftHand; public GameObject RightHand; private GrabbingHand? hand = null; // nullable private SmartHandPresence currentHand = null; private bool isGrabbing; // Tracks all hands currently inside the trigger private HashSet handsInTrigger = new HashSet(); public void ManifestDoorHand() { if (currentHand == null || hand == null) return; isGrabbing = true; switch (hand.Value) { case GrabbingHand.Left: RightHand.SetActive(false); LeftHand.SetActive(true); Debug.Log("Dissapearing hand"); break; case GrabbingHand.Right: LeftHand.SetActive(false); RightHand.SetActive(true); Debug.Log("Dissapearing hand"); break; } } public void DeManifestDoorHand() { isGrabbing = false; LeftHand.SetActive(false); RightHand.SetActive(false); if (currentHand == null) return; } private void OnTriggerEnter(Collider other) { if (isGrabbing) return; // IMPORTANT: in case hands have multiple colliders SmartHandPresence playerHand = other.GetComponentInParent(); if (playerHand == null) return; handsInTrigger.Add(playerHand); currentHand = playerHand; string name = playerHand.gameObject.name; if (name.Contains("left", System.StringComparison.OrdinalIgnoreCase)) { hand = GrabbingHand.Left; } else if (name.Contains("right", System.StringComparison.OrdinalIgnoreCase)) { hand = GrabbingHand.Right; } } private void OnTriggerExit(Collider other) { if (isGrabbing) return; SmartHandPresence playerHand = other.GetComponentInParent(); if (playerHand == null) return; handsInTrigger.Remove(playerHand); // If no hands remain, clear everything if (handsInTrigger.Count == 0) { currentHand = null; hand = null; } else { // Pick any remaining hand as current foreach (var remainingHand in handsInTrigger) { currentHand = remainingHand; string name = remainingHand.gameObject.name; hand = name.Contains("left", System.StringComparison.OrdinalIgnoreCase) ? GrabbingHand.Left : GrabbingHand.Right; break; } } } }