【发布时间】:2019-02-13 16:13:45
【问题描述】:
我想让我的角色在滑动屏幕或触摸 Unity 3D 手机中的虚拟按钮时向左或向右移动,这是玩家用键盘键移动它的移动脚本,但是我希望它适用于移动设备。
void FixedUpdate ()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("d")) // If the player is pressing the "d" key
{
// Add a force to the right
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("a")) // If the player is pressing the "a" key
{
// Add a force to the left
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
【问题讨论】:
标签: c# android visual-studio unity3d