How to Make car intersections

Hey guys. I am making a car script and I am working on Intersections and having a bit of trouble. The way im planning on doing it is the car cast a ray in front of it. When that ray hits an intersection collider then car will stop and it will add a number to the intersection script. Then the intersection script will tell the car whether or not it is his turn to go. My problem is how do I make sure the car only accesses the intersection script that the car is at rather than hitting them all or only a random one?

Most forms of Raycast, take a RaycastHit parameter. This parameter tells you about the object hit. So inside your raycast logic you might do something like:

if (hit.tag == "Intersection") {
    var intersectionScript = hit.collider.GetComponent(IntersectionScript);
    // Use the specific intersection script.

So this will give you a reference to the ‘IntersectionScript’ attached to the object hit by the raycast.