Make the character respond to traffic lights

I am trying to build a traffic light system where the pedestrians respond to the lights but I am not sure how. My codes do not seem to work

Hello @MeganPein. The first step to setting this up is adding your colliders. Add them to the traffic lights prefab. Make sure it is set to Is Trigger. Do this for you ped’s too. Also, create a tag for the ped’s. Also, both objects need a Rigidbody, with the gravity set to 0.

The next step is to check if a ped hits the collider. To do this, use OnTriggerEnter (Docs at the bottom). Then, check the tag of the object. If the tag is "Pedestrian", check what color the light is.

After this, access the ped’s script through the tags Transform and send it a message to react however nessacerry.

Since that is a mouthful, here is a scripted example:

void OnTriggerEnter(Collider other)
{
    if (other.tag == "Pedestrian")
    { 
        PedestrianScript PEDScript = other.transform.GetComponent<PedestrianScript>();
        //Check what light color is.
        //Decide action based off of that.
    }        
}

I hope that was helpful. :slight_smile:

OnTriggerEnter

I am not sure how to use colliders to create that system. Do provide a guide on it. Thanks.

Can you please stop creating new threads for the same issue? This is considered duplicate. Thanks.