void OnTriggerStay(Collider col)
    {
        switch (col.gameObject.tag)
        {
        case Constants.Tag.TagVehicleStopZoneAvenueRight:
            TrafficLightsController trafficControllerR = col.transform.GetComponentInParent <TrafficLightsController>();
            trafficLightState = trafficControllerR.trafficRight;
            break;

        case Constants.Tag.TagVehicleStopZoneAvenueLeft:
            TrafficLightsController trafficControllerL = col.transform.GetComponentInParent <TrafficLightsController>();
            trafficLightState = trafficControllerL.trafficLeft;
            break;
        }
    }
Example #2
0
    public virtual void Start()
    {
        this.AddComponents();
        gameManager = GameObject.FindGameObjectWithTag(Const.tagGAMEMANAGER).GetComponent <GameManager>();
        this.SetDestination(gameManager.timeOfDay);
        trafficLightController           = GameObject.FindGameObjectWithTag(Const.tagTRAFFICLIGHTCONTROLLER).GetComponent <TrafficLightsController>();
        trafficLightStopMaterial         = trafficLightController.trafficLightStopMaterial;
        simulationManager                = GameObject.FindGameObjectWithTag(Const.tagSIMULATIONMANAGER).GetComponent <SimulationManager>();
        go.gameObject.transform.position = currentDestination.destination.transform.position;
        this.NotifyObservers(this.role, true);
        checkTrafficLight = false;

        startSpeed = agent.speed;
        //    this.NotifyObservers(true);
    }
    void OnTriggerEnter(Collider col)
    {
        switch (col.gameObject.tag)
        {
        // if encounters a crosswalk with the player about to cross, stop
        case Constants.Tag.TagVehicleStopZone:
            IntentionToCrossController intentionController = col.transform.GetComponentInParent <IntentionToCrossController>();

            if (intentionController != null && intentionController.HasIntention())
            {
                go = false;
                Invoke("Go", settings.vehicleSettings.vehicleCrosswalkWaitTime);
            }
            break;

        case Constants.Tag.TagVehicleStopZoneAvenueRight:
            TrafficLightsController trafficControllerR = col.transform.GetComponentInParent <TrafficLightsController>();
            trafficLightState = trafficControllerR.trafficRight;
            if (trafficControllerR != null && (trafficControllerR.trafficRight == TrafficLightState.Red || trafficControllerR.trafficRight == TrafficLightState.Yellow))
            {
                go = false;
            }

            break;

        case Constants.Tag.TagVehicleStopZoneAvenueLeft:
            TrafficLightsController trafficControllerL = col.transform.GetComponentInParent <TrafficLightsController>();
            trafficLightState = trafficControllerL.trafficRight;
            if (trafficControllerL != null && (trafficControllerL.trafficRight == TrafficLightState.Red || trafficControllerL.trafficRight == TrafficLightState.Yellow))
            {
                go = false;
            }

            break;


        // if encounters a car, means that the car's going slower. Must slow down and match his pace.
        // if the car is stopping, must stop too.
        case Constants.Tag.TagVehicleWarningZone:
            VehicleController carAhead = col.GetComponentInParent <VehicleController>();

            // if this event was thrown by the car behind
            if ((direction == Utils.VehicleDirection.Left && transform.position.x > carAhead.transform.position.x) || (direction == Utils.VehicleDirection.Right && transform.position.x < carAhead.transform.position.x))
            {
                brake += 0.03f;
                if (carAhead.go)
                {
                    maxSpeed = carAhead.maxSpeed;

                    if (carAhead.currentSpeed > currentSpeed)
                    {
                        currentSpeed = carAhead.currentSpeed;
                    }
                }
                else
                {
                    go = false;
                }
            }

            break;
        }
    }
Example #4
0
 void Awake()
 {
     lights = GetComponent <TrafficLightsController>();
 }