我正在开发一个节奏游戏,想让它与吉他英雄的控制器兼容。
使用遗弃的输入系统,我能够读取 Guitar 的按键 (按钮)。好的!然而,我无法读取 Strums(打击)。我已经在 Clone Hero中测试了我的吉他,知道问题不出在设备上。我尝试了使用I有 Xbox 360的Xplorer吉他,如果这会改变什么。我的 Unity 的版本是 2022。
我的问题是:
-当前设置下,我是否可以让它工作?如何?
-在不同的 Unity 版本下会更好吗?
-是否还有其他吉他控制器比 Unity 更容易与之兼容?
以下是我的代码:
private void Start()
{
_prevStrum = Input.GetAxisRaw("5th Axis");
}
private void Update()
{
// 刀边
if (Input.GetKeyDown(KeyCode.JoystickButton0)) OnGreen?.Invoke();
if (Input.GetKeyDown(KeyCode.JoystickButton1)) OnRed?.Invoke();
if (Input.GetKeyDown(KeyCode.JoystickButton3)) OnYellow?.Invoke();
if (Input.GetKeyDown(KeyCode.JoystickButton2)) OnBlue?.Invoke();
if (Input.GetKeyDown(KeyCode.JoystickButton4)) OnOrange?.Invoke();
float strum = Input.GetAxisRaw("5th Axis");
float delta = strum - _prevStrum;
if (_strumArmed)
{
if (delta >= _strumSensitivity) { OnStrumDown?.Invoke(); _strumArmed = false; }
else if (delta <= -_strumSensitivity) { OnStrumUp?.Invoke(); _strumArmed = false; }
}
// 等待值稳定 (delta 重新成为噪音时 )
if (!_strumArmed && Mathf.Abs(delta) < 0.05f)
{
_strumArmed = true;
}
_prevStrum = strum;
}
评论 (0)