using UnityEngine.XR.Interaction.Toolkit; namespace UnityEngine.XR.Content.Interaction { /// /// Initializes an attach point to match the initial scene position of the object it is containing. /// public class AutoSocketAttach : MonoBehaviour { [SerializeField] [Tooltip("The Socket Interactor that controls this socket attach point.")] XRSocketInteractor m_ControllingInteractor; void Start() { // If there is an existing interactable, we match its position so the object does not move if (m_ControllingInteractor == null) m_ControllingInteractor = GetComponentInParent(); if (m_ControllingInteractor == null) { Debug.LogWarning("Script is not associated with an XRSocketInteractor and will have no effect.", this); return; } if (m_ControllingInteractor.startingSelectedInteractable == null) { Debug.Log("AutoSocketAttach does not have a starting selected interactable to match its position.", this); return; } var targetTransform = m_ControllingInteractor.startingSelectedInteractable.GetAttachTransform(m_ControllingInteractor); transform.SetPositionAndRotation(targetTransform.position, targetTransform.rotation); } } }