Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to retreave a value from an interactable when he is fixed on a socket ?

Discussion in 'XR Interaction Toolkit and Input' started by Spooky92, Mar 30, 2023.

  1. Spooky92

    Spooky92

    Joined:
    May 8, 2022
    Posts:
    9
    Hello everybody,
    I'm working on an electrical circuit in VR with the XR Interaction Toolkit. All the calculations for the circuit are made by a Circuit Manager (script). He should get all the informations from the different sockets(I tuned the Socket Script). But how can the socket read/get the resistance value (for example) from a tuned interactable script once this interactable is selected on the socket ?

    Thank you for your help.
     
    Last edited: Apr 1, 2023
  2. Spooky92

    Spooky92

    Joined:
    May 8, 2022
    Posts:
    9
    Hello,
    after some research is seems that the socket base script (XRSocketInteractor) is filling up a list of all colliders that stays in touch of it, trough a contact monitor.

    Code (CSharp):
    1. readonly List<Collider> m_StayedColliders = new List<Collider>();
    2.  
    3.         readonly TriggerContactMonitor m_TriggerContactMonitor = new TriggerContactMonitor();

    Could I retrieve the last member of this collider list, in order to get the gameObject name ?

    I have created a socketWithTag class inherited from XRSocketInteractor. And added a public function wich will be called onSelectedEnter event. But I didn't get how to acces the collider list from my script.

    Code (CSharp):
    1. public void ValueTransfert()
    2.     {
    3.         if (targetTag == "Resistor")
    4.         {
    5.             Collider interactableCollider;
    6.             GameObject interactableObject;
    7.             string interactableName;
    8.  
    9.             interactableCollider = m_StayedColliders.Last();
    10.             interactableObject= interactableCollider.gameObject;
    11.             interactableName = interactableObject.name;
    12.  
    13.             CircuitManager.instance.resistance[socketNumber - 1] = int.Parse(interactableName);
    14.         }