Unity3D中的错误“已经注册了名为XXX的虚拟轴。”在VirtualInput.cs

时间:2019-09-08 14:41:34

标签: c# android visual-studio unity3d

请帮忙。 Unity3D中存在标准资产脚本的问题。 即在VirtualInput.cs

在Internet上,有其他版本的Unity3D上的代码更正的答案。 这是另一种方法

public void RegisterVirtualAxis(CrossPlatformInputManager.VirtualAxis axis)
        {
            // check if we already have an axis with that name and log and error if we do
            if (m_VirtualAxes.ContainsKey(axis.name))
            {
                Debug.LogError("There is already a virtual axis named " + axis.name + " registered.");
            }
            else
            {
                // add any new axes
                m_VirtualAxes.Add(axis.name, axis);

                // if we dont want to match with the input manager setting then revert to always using virtual
                if (!axis.matchWithInputManager)
                {
                    m_AlwaysUseVirtual.Add(axis.name);
                }
            }
        }

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法,并重新制作了方法:

public void RegisterVirtualAxis(CrossPlatformInputManager.VirtualAxis axis)
        {
            // check if we already have an axis with that name and log and error if we do
            if (m_VirtualAxes.ContainsKey(axis.name))
            {
                //Debug.LogError("There is already a virtual axis named " + axis.name + " registered.");
                m_VirtualAxes.Remove(axis.name);

                m_VirtualAxes.Add(axis.name, axis);

                if (!axis.matchWithInputManager)
                {
                    m_AlwaysUseVirtual.Add(axis.name);
                }
            }
            else
            {
                // add any new axes
                m_VirtualAxes.Add(axis.name, axis);

                // if we dont want to match with the input manager setting then revert to always using virtual
                if (!axis.matchWithInputManager)
                {
                    m_AlwaysUseVirtual.Add(axis.name);
                }
            }
        }