Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Switching between Snap and Continuous turn in real time with UI dropdown

Discussion in 'XR Interaction Toolkit and Input' started by SP4ZE, Dec 2, 2022.

  1. SP4ZE

    SP4ZE

    Joined:
    Jul 31, 2022
    Posts:
    6
    Heyy, im trying to code a UI dropdown which will allow player to switch his turning controls from snap to continuous and vice versa.

    I want to achieve this by simply turning off these components in the locomotion but Im not sure how to reference them, I tried, but SetActive didn't seem to work. Would kindly appreciate any info

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6. using UnityEngine.XR.Interaction.Toolkit;
    7.  
    8. public class UI_Turning : MonoBehaviour
    9. {
    10.     public TMPro.TMP_Dropdown dropdown;
    11. // TRYING TO REFERENCE LOCOMOTION COMPONENTS
    12.     public GameObject locomotion;
    13.     public ActionBasedSnapTurnProvider snapTurn;
    14.     public ActionBasedContinuousTurnProvider continuousTurn;
    15.  
    16.     void Start()
    17.     {
    18.     snapTurn = locomotion.GetComponent<ActionBasedSnapTurnProvider>();
    19.     continuousTurn = locomotion.GetComponent<ActionBasedContinuousTurnProvider>();
    20.     }
    21.  
    22.     public void TurningOptions()
    23.     {
    24. // TRYING TO DISABLE / ENABLE COMPONENTS IN LOCOMOTION
    25.         if (dropdown.value == 0)
    26.         {
    27.             Debug.Log("Continuous turning options");
    28.             locomotion.GetComponent<ActionBasedSnapTurnProvider>().enabled = false;
    29.             locomotion.GetComponent<ActionBasedContinuousTurnProvider>().enabled = true;
    30.         }
    31.  
    32.         if (dropdown.value == 1)
    33.         {
    34.             Debug.Log("Snap turning options");
    35.             locomotion.GetComponent<ActionBasedSnapTurnProvider>().enabled = true;
    36.             locomotion.GetComponent<ActionBasedContinuousTurnProvider>().enabled = false;
    37.         }
    38.     }
    39. }
    40.  
     
    Last edited: Dec 2, 2022
  2. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    616
    Seems you posted this message in two places. I replied to the other one.