UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"move vehicle with Accelerometer or Gyroscope"
public class Vehicle : MonoBehaviour { Rigidbody2D rb; float dirX; float moveSpeed = 20f; void Start () { rb = GetComponent<Rigidbody2D> (); } void Update () { dirX = Input.acceleration.x * moveSpeed; transform.position = new Vector2 (Mathf.Clamp (transform.position.x, -7.5f, 7.5f), transform.position.y); } void FixedUpdate() { rb.velocity = new Vector2 (dirX, 0f); } }