Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
585 B
2
Indexable
using UnityEngine;

public class CarController : MonoBehaviour
{
    public float speed = 10f;
    public float rotationSpeed = 100f;

    private void Update()
    {
        // Get user input for movement and rotation
        float moveInput = Input.GetAxis("Vertical");
        float rotateInput = Input.GetAxis("Horizontal");

        // Move the car forward/backward
        transform.Translate(Vector3.forward * moveInput * speed * Time.deltaTime);

        // Rotate the car left/right
        transform.Rotate(Vector3.up * rotateInput * rotationSpeed * Time.deltaTime);
    }
}