void Start()
    {
        int chosenSpeedIndex = Random.Range(0, 5);

        switch (chosenSpeedIndex)
        {
        case 0:
            maxSpeed = Utils.VehicleSpeed.Going20;
            break;

        case 1:
            maxSpeed = Utils.VehicleSpeed.Going40;
            break;

        case 2:
            maxSpeed = Utils.VehicleSpeed.Going50;
            break;

        case 3:
            maxSpeed = Utils.VehicleSpeed.Going70;
            break;

        case 4:
            maxSpeed = Utils.VehicleSpeed.Going90;
            break;
        }

        guiText = (Text)GetComponentInChildren <Text>();
    }
    /*
     * Sets current car speed
     */
    public void SetCurrentSpeed(Utils.VehicleSpeed speed)
    {
        float newMin   = Constants.Vehicle.VehicleMinSpeedModel;
        float newMax   = Constants.Vehicle.VehicleMaxSpeedModel;
        float oldMin   = Constants.Vehicle.VehicleMinSpeedView;
        float oldMax   = Constants.Vehicle.VehicleMaxSpeedView;
        float oldValue = (float)speed;
        float newValue = (((oldValue - oldMin) * (newMax - newMin)) / (oldMax - oldMin)) + newMin;


        maxSpeed = (Utils.VehicleSpeed)newValue;
    }
 public SpeedLimitController()
 {
     current          = new List <Road>();
     activeIndex      = -1;
     currentRoadSpeed = 0;
 }
    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;
        }
    }
Пример #5
0
 public Road(float topLimit, float bottomLimit, Utils.VehicleSpeed speed)
 {
     top        = topLimit;
     bot        = bottomLimit;
     speedlimit = speed;
 }