artcl0ud_rc-racer-prototype/Assets/Scripts/Wheel.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Wheel : MonoBehaviour
{
    public bool isSteerable;
    public bool isInverseSteerable;
    public bool isPowered;

    public float SteerAngle { get; set; }
    public float Torque { get; set; }

    private WheelCollider wheelCollider;
    private Transform wheelTransform;

    void Start()
    {
        wheelCollider = GetComponentInChildren<WheelCollider>();
        wheelTransform = GetComponentInChildren<MeshRenderer>().GetComponent<Transform>();
    }

    void Update()
    {
        wheelCollider.GetWorldPose(out Vector3 pos, out Quaternion rot);
        wheelTransform.position = pos;
        wheelTransform.rotation = rot;
    }

    private void FixedUpdate()
    {
        if(isSteerable)
        {
            wheelCollider.steerAngle = SteerAngle * (isInverseSteerable ? -1 : 1);
        }

        if(isPowered)
        {
            wheelCollider.motorTorque = Torque;
        }
    }
}

