using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InputManager : MonoBehaviour
{
// Start is called before the first frame update
public float throttle;
public float steer;
// Update is called once per frame
void Update()
{
throttle = Input.GetAxis("Vertical");
steer = Input.GetAxis("Horizontal");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(InputManager))]
public class CarController : MonoBehaviour
{
public InputManager im;
public List throttlewheels;
public List steeringwheels;
public float force = 20000f;
void Start()
{
im = GetComponent();
}
void FixedUpdate()
{
foreach (WheelCollider wheel in throttlewheels) ;
{
wheel.motorTorque = force * Time.deltaTime * im.throttle;
}
foreach (WheelCollider Wheel in steeringwheels) ;
wheel.steerAngle = maxTurn * im.steer;
}
}
,
↧