我正在开发一款 FPS 游戏,我正在使用标准 Assets 附带的 FPSController
。我正在开发一个 Gamepad Controller 来控制手机游戏。
配置 Controller 的所有输入后,我想替换如下代码:
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
代码应该如下所示:
if(Application.platform == RuntimePlatform.Android)
{
if (!m_Jump)
{
m_Jump = Input.GetButtonDown("Joystick A");
}
}else{
if (!m_Jump)
{
m_Jump = CrossPlatformInputManager.GetButtonDown("Jump");
}
}
What is the best way to modify the
FPS Controller
Scripts and add These Inputs?
提前致谢。
最佳答案
您可以通过不需要编辑或添加任何附加代码的方式来解决这个问题。
在“编辑”>“项目设置”>“输入”下,您可以找到 InputManager 和“轴”。在这里您会找到所有预定义的输入值及其对应的按钮。如果展开输入轴“Jump”,您会看到它有一个名为“Positive button”的变量(默认为空格)和一个空的“alternative button”。如果您将所需的按钮添加到备用按钮部分,它将在按下游戏 handle 上的相应按钮时触发 CrossPlatformInputManager.GetButtonDown("Jump");
操作。
如果您喜欢扩展列表并添加您自己的触发器,您也可以。
输入管理器为键盘和鼠标、操纵杆和游戏 handle 提供开箱即用的支持 更多信息可以在文档中找到 here
这样做的好处是不需要额外的代码或条件。这可能是最优化的解决方法
关于c# - Unity 覆盖 `StandardAssetsScripts` 的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51721101/