我有无尽的跑步游戏,我可以使用键盘键左右移动播放器,但我不知道如何在移动设备中左右移动播放器?请任何人给我一个脚本让我的播放器在移动设备上左右移动...
这是我的脚本
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
// This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;
public float forwardForce = 3000f; // Variable that determines the forward force
public float sidewaysForce = 43f;
// Variable that determines the sideways force
// We marked this as "Fixed"Update because we
// are using it to mess with physics
void FixedUpdate ()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("k")) // If the player is pressing the "d" key
{
// Add a force to the right
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}
if (Input.GetKey("d")) // If the player is pressing the "a" key
{
// Add a force to the left
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
}
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
}