private void OnTriggerEnter(Collider other)
        {
            if (_isStopped && !_canCollide && other == this)
            {
                return;
            }

            if (other.transform.tag == "TrafficLight")
            {
                Debug.Log(transform.name + " Colliding with Traffic Light");

                // Check is this is the frontmost car
                if (_frontCar != null && !_isFront)
                {
                    Debug.Log(transform.name + " _frontCar is not null or _isFront is false - OnTrigger TrafficLight************************");
                    return;
                }

                _isFront  = true;
                _frontCar = this;

                // Add car to the traffic list
                _trafficCont = other.GetComponent <TrafficLightScript>();
                _trafficCont.AddToTrafficList(this);

                StopCar();
            }

            if (other.transform.tag == "Vehicle")
            {
                Debug.Log(transform.name + " Colliding with " + other.transform.name);

                StopCar();

                // Get the collided car's script
                CarScript otherCar = other.GetComponent <CarScript>();

                // Get reference to the front car
                _frontCar = otherCar._frontCar;

                if (_frontCar == null)
                {
                    Debug.Log(transform.name + " : _frontCar of " + other.transform.name + "is null - OnTrigger Vehicle**************************");
                    return;
                }

                // Add car to the traffic list
                _trafficCont = otherCar._trafficCont;
                _trafficCont.AddToTrafficList(this);
            }
        }
        IEnumerator CanCollideCooldown()
        {
            yield return(new WaitForSeconds(3.0f));

            _canCollide = true;

            //Reset all members
            Destroy(_temp);
            _frontCar    = null;
            _trafficCont = null;

            _isStopped = false;
            _isFront   = false;
        }
Exemplo n.º 3
0
    public void AddToTrafficList(PathCreation.CarScript car)
    {
        if (!_listTraffic.Contains(car))
        {
            _listTraffic.Add(car);
        }

        if (_listTraffic.Count > _amtCarToStopSpawn)
        {
            stopCarSapwn?.Invoke(false);
        }
        else
        {
            stopCarSapwn?.Invoke(true);
        }
    }