using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR; public class Switch_Models : MonoBehaviour { bool incrementDone = false; private enum ControllerSide { Left_Controller, Right_Controller, } [SerializeField] private ControllerSide m_controller; private InputDeviceCharacteristics m_caracteristics; private bool m_debugMode = true; private GameObject[] Models; private int _CurrentModel; public int CurrentModel { get { return _CurrentModel; } set { if (_CurrentModel != value && Models.Length > 0){ Models[_CurrentModel].SetActive(false); if (value >= Models.Length){ _CurrentModel = 0; } else if(value < 0){ _CurrentModel = Models.Length - 1; } else {_CurrentModel = value;} Models[_CurrentModel].SetActive(true); } } } void Start () { if (DebugLogger.current == null) m_debugMode = false; if (m_controller == ControllerSide.Left_Controller) { m_caracteristics = InputDeviceCharacteristics.Left; } else { m_caracteristics = InputDeviceCharacteristics.Right; } Models = new GameObject[transform.childCount]; for(int i = 0 ; i < Models.Length ; i++){ Models[i] = transform.GetChild(i).gameObject; Models[i].SetActive(false); } if (Models.Length > 0){ Models[0].SetActive(true); _CurrentModel = 0; } } void Update () { List<InputDevice> m_device = new List<InputDevice>(); InputDevices.GetDevicesWithCharacteristics(m_caracteristics, m_device); if (m_device.Count == 1) { CheckController(m_device[0]); } else { if (m_debugMode) DebugLogger.current.AddLine("Controlller not found"); } } private void CheckController(InputDevice d) { bool primaryButtonDown = false; d.TryGetFeatureValue(CommonUsages.primaryButton, out primaryButtonDown); incrementDone = false; if (primaryButtonDown) { //if (m_debugMode) DebugLogger.current.AddLine("Primary Button down"); CurrentModel++; } else { if (m_debugMode) DebugLogger.current.AddLine("Primary Button up"); } bool secondaryButtonDown = false; d.TryGetFeatureValue(CommonUsages.secondaryButton, out secondaryButtonDown); if (secondaryButtonDown) { if (m_debugMode) DebugLogger.current.AddLine("Secondary Button down"); CurrentModel--; } else { if (m_debugMode) DebugLogger.current.AddLine("Secondary Button up"); } } } Hello, I would like to increment or decrement the CurrentModel variable.. but the primarybutton and secondary are always true !! could you help me ? many thanks
@manubabu2638 Жыл бұрын
i need this tutorial set up please
@manubabu2638 Жыл бұрын
can you please send me where can i get this project
@sameastridge3398 Жыл бұрын
I've been looking all over for this, thanks
@levibusching4602 Жыл бұрын
very helpful
@zillaKTF Жыл бұрын
Thank you so much! This was perfect for what I needed.
@zillaKTF Жыл бұрын
Thank you! This was exactly what I was looking for! I needed to add controller support to an existing Unity project from 2019 that previously only worked with 3DOF headset movement. It was implemented with the legacy input system using XR Legacy Input Helper and XR Plugin Management packages. More recent videos about adding XR controller support use the new input system, which I can't use without overhauling the whole project. With this video I got basic controller movement working in just a few minutes ^^
@nikkelei Жыл бұрын
very nice simple tutorial
@nothingnothingnothing862 Жыл бұрын
dont think about his subscriber count
@Wayfaringwolf3 жыл бұрын
Thank you!
@mjerzzie13 жыл бұрын
Thank you for this explaination!
@ArchDawnDev4 жыл бұрын
Thank you so much! I don't know why I was having so much trouble with this, but cleared up any confusion I had.