12345678910111213141516171819202122232425262728293031 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class WheelDrive : MonoBehaviour
- {
- private WheelCollider wheelCollider;
- public float torque = 200;
- // Start is called before the first frame update
- void Start()
- {
- wheelCollider = GetComponent<WheelCollider>();
- }
- private void Go(float accel)
- {
- accel = Mathf.Clamp(accel, -1, 1);
- float thrustTorque = accel * torque;
- wheelCollider.motorTorque = thrustTorque;
- }
-
- // Update is called once per frame
- void Update()
- {
- float a = Input.GetAxis("Vertical");
- Go(a);
- }
- }
|