using UnityEngine;

public class ForcedDriveInputController : MonoBehaviour 
{
    private Engine engine;
    private Brakes brakes;
    private SteeringWheel steeringWheel;
    private Rigidbody2D r2;

    void Start()
    {
        engine = GetComponent<Engine>();
        brakes = GetComponent<Brakes>();
        steeringWheel = GetComponent<SteeringWheel>();
        r2 = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        engine.ThrottleFactor = 1f;
        brakes.BrakeFactor = 0f;

        if (SteeringLeft())
            steeringWheel.SteeringFactor = -1f;
        else if (SteeringRight())
            steeringWheel.SteeringFactor = 1f;
        else
            steeringWheel.SteeringFactor = 0f;
    }

    private static bool SteeringLeft()
    {
        return Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
    }

    private static bool SteeringRight()
    {
        return Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
    }
}
