void OnTriggerEnter(Collider col) { // simulates click on a car if (col.gameObject.CompareTag(Constants.Tag.TagVehicle)) { gameObject.SetActive(false); VehicleController vehicle = col.gameObject.GetComponent <VehicleController>(); bool isVehicleOnCurrentRoad = gameManager.speedLimitController.IsVehicleOnCurrentRoad(col.gameObject.transform.position.z); if (isVehicleOnCurrentRoad) { if (vehicle.GetCurrentSpeed() > (float)gameManager.speedLimitController.currentRoadSpeed) { vehicle.SetCurrentSpeed(gameManager.speedLimitController.currentRoadSpeed); gameManager.scoreController.AddScoreVehicleHit(); //Debug.Log("WIN POINTS because vehicle speed = " + vehicle.GetCurrentSpeed() + " and road is " + 0 + gameManager.speedLimitController.currentRoadSpeed); } else { gameManager.scoreController.SubScoreVehicleHit(); //Debug.Log("LOSE POINTS because vehicle speed = " + vehicle.GetCurrentSpeed() + " and road is " + 0 + gameManager.speedLimitController.currentRoadSpeed); } } } }
private void OnCheckCongestedAreasVehicle() { Vector3 vWorldPosition = _transformTrafficSensor.TransformPoint(Vector3.zero); Collider[] collider = Physics.OverlapSphere(vWorldPosition, 30.0f); _iCongestedAreasVehicleCount = 0; _fCongestedAreasVehicleAverageCurrentSpeed = 0.0f; _fCongestedAreasVehicleAverageMaxSpeed = 0.0f; if (collider.Length > 0) { for (int i = 0; i < collider.Length; ++i) { if (collider[i].gameObject.layer == LayerMask.NameToLayer("Vehicle")) { ++_iCongestedAreasVehicleCount; VehicleController vehicleController = collider[i].GetComponent <VehicleController>(); if (vehicleController) { _fCongestedAreasVehicleAverageCurrentSpeed += vehicleController.GetCurrentSpeed(); _fCongestedAreasVehicleAverageMaxSpeed += vehicleController.GetMaxSpeed(); } } } if (_iCongestedAreasVehicleCount > 0) { _fCongestedAreasVehicleAverageCurrentSpeed = _fCongestedAreasVehicleAverageCurrentSpeed / _iCongestedAreasVehicleCount; _fCongestedAreasVehicleAverageMaxSpeed = _fCongestedAreasVehicleAverageMaxSpeed / _iCongestedAreasVehicleCount; } else { _fCongestedAreasVehicleAverageCurrentSpeed = 1.0f; _fCongestedAreasVehicleAverageMaxSpeed = 1.0f; } } _fCongestedAreasValue = GetCongestedAreasValue(); Vector3 vA = new Vector3(_sliderCongestedAreas.value, 0.0f, 0.0f); Vector3 vB = new Vector3(_fCongestedAreasValue, 0.0f, 0.0f); Vector3 vResult = Vector3.Lerp(vA, vB, Time.deltaTime * 2.0f); _sliderCongestedAreas.value = vResult.x; }