模拟键盘按钮使用 Input.GetAxis ("Horizontal")
Simulate keyboard buttons to use Input.GetAxis ("Horizontal")
我已经坚持了一段时间,非常感谢你的帮助。
我需要将游戏移植到移动设备,因此我需要更改控制方案以考虑点击。
我想继续使用 Input.GetAxis ("Horizontal"),因为游戏是围绕它构建和平衡的,只要玩家点击 [=] 就模拟 left/right 击键31=] 屏幕的一侧。
这有可能吗?
更新时:
touchMove()
playerPosition.x += Input.GetAxis ("Horizontal") * playerVelocity;
transform.position = playerPosition;
检查水龙头
private void touchMove()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.position.x < Screen.width/2)
{
//simulate a left keyboard push
}
else if (touch.position.x > Screen.width/2)
{
//simulate a left keyboard push
}
}
}
经过一些研究,似乎不可能有一个为输入设置值的脚本。
作为替换,您可以使用自己的中间函数,它会考虑您想要的任何内容。
示例:
private int GetAxisHorizontal()
{
// Get whatever should return your axis value
if(Input.touches > 0) {... return value;}
else return Input.GetAxis("Horizontal");
}
您可以像正常功能一样使用它:
playerPosition.x += GetAxisHorizontal() * playerVelocity;
最后我只是加了一个力来模拟运动,拖动来模拟减速。它是 getAxis 的一个很好的替代品。
我需要进一步调整我的代码,但这应该适用于键盘和触摸输入。
我做了 r3x 所做的,this 现在是我的播放器脚本。它具有移动和键盘控件,以及内置的多个绑定选项(更改 KeyBindings
class)。
(代码还是有点问题)
编辑:只是想注意这个脚本中的很多部分都获得了 keys/mouse 位置并对其进行 lerp-ing 以使其平滑。降低 / 40f
以增加平滑度。
我已经坚持了一段时间,非常感谢你的帮助。
我需要将游戏移植到移动设备,因此我需要更改控制方案以考虑点击。
我想继续使用 Input.GetAxis ("Horizontal"),因为游戏是围绕它构建和平衡的,只要玩家点击 [=] 就模拟 left/right 击键31=] 屏幕的一侧。
这有可能吗?
更新时:
touchMove()
playerPosition.x += Input.GetAxis ("Horizontal") * playerVelocity;
transform.position = playerPosition;
检查水龙头
private void touchMove()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.position.x < Screen.width/2)
{
//simulate a left keyboard push
}
else if (touch.position.x > Screen.width/2)
{
//simulate a left keyboard push
}
}
}
经过一些研究,似乎不可能有一个为输入设置值的脚本。
作为替换,您可以使用自己的中间函数,它会考虑您想要的任何内容。
示例:
private int GetAxisHorizontal()
{
// Get whatever should return your axis value
if(Input.touches > 0) {... return value;}
else return Input.GetAxis("Horizontal");
}
您可以像正常功能一样使用它:
playerPosition.x += GetAxisHorizontal() * playerVelocity;
最后我只是加了一个力来模拟运动,拖动来模拟减速。它是 getAxis 的一个很好的替代品。
我需要进一步调整我的代码,但这应该适用于键盘和触摸输入。
我做了 r3x 所做的,this 现在是我的播放器脚本。它具有移动和键盘控件,以及内置的多个绑定选项(更改 KeyBindings
class)。
(代码还是有点问题)
编辑:只是想注意这个脚本中的很多部分都获得了 keys/mouse 位置并对其进行 lerp-ing 以使其平滑。降低 / 40f
以增加平滑度。