I want to see the traffic flow in an intersection, realtime, for 60seconds, but It doesn’t work.
This is my function:
private void Start()
{
_timer = 0;
_nrOfCars = 0;
}
private void Update()
{
if ( _timer <60 )
_timer += Time.deltaTime;
else
{
Debug.Log(_nrOfCars + " " + _timer );
TrafficFlow = _nrOfCars / (_timer);
_timer = 0;
_nrOfCars = 0;
}
}
/// <summary>
/// Check if the car is near intersection
/// </summary>
/// <param name="other"></param>
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Car")
{
_nrOfCars++;
other.GetComponent<CarEngine>().Intersection = true;
}
}