Search Unity

Activate/deactive DualTouchControls at runtime breaks functionality?

Discussion in 'Scripting' started by John1515, Aug 20, 2017.

  1. John1515

    John1515

    Joined:
    Nov 29, 2012
    Posts:
    248
    I have Unity's DualTouchControls in my scene to control a car and it works.
    But the controls shouldn't be visible right from the start, so I deactivate/active them by script.
    This however breaks its functionality. Also in the editor it is not possible to deactivate these controls so I guess that is something one should not do.

    I get "There is already a virtual axis named Horizontal registered." which explains the problem, but don't know how to solve it.

    I could of course do quirky stuff: move the touchcontrols out of the screen when I don't need it but that doesn't seem right.

    EDIT: ok fixed:


    In TouchPad.cs, replace CreateVirtualAxis() with this:

    Code (CSharp):
    1. void CreateVirtualAxes()
    2.         {
    3.             // set axes to use
    4.             m_UseX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
    5.             m_UseY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
    6.  
    7.             // create new axes based on axes to use
    8.             if (m_UseX)
    9.             {
    10.                 if (CrossPlatformInputManager.AxisExists(horizontalAxisName))
    11.                 {
    12.                     CrossPlatformInputManager.UnRegisterVirtualAxis(horizontalAxisName);
    13.                 }
    14.                 m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
    15.                 CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
    16.             }
    17.             if (m_UseY)
    18.             {
    19.                 if (CrossPlatformInputManager.AxisExists(verticalAxisName))
    20.                 {
    21.                     CrossPlatformInputManager.UnRegisterVirtualAxis(verticalAxisName);
    22.                 }
    23.                 m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
    24.                 CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
    25.             }
    26.         }
    it is
    Code (CSharp):
    1. if (CrossPlatformInputManager.AxisExists(horizontalAxisName))
    2.                 {
    3.                     CrossPlatformInputManager.UnRegisterVirtualAxis(horizontalAxisName);
    4.                 }
    that is missing in Unity's own implementation.
     
    Last edited: Aug 20, 2017