Beispiel #1
0
    public void SpawCar()
    {
        // if the car numbers hit the max,
        // do not create more cars
        if (TrafficManager.IsCarMaximum())
        {
            return;
        }

        // test if all the road is empty
        foreach (Road r in roads)
        {
            if (TestForward(r) != null)
            {
                return;
            }
        }

        if (carPrefabs.Length > 1)
        {
            for (int i = 0; i < 1; i++)
            {
                if ((i == 0) && (RedSwitch))
                {
                    GameObject carObj = Instantiate(carPrefabs[0]);

                    Car carCom = carObj.GetComponent <Car>();
                    carCom.SetFromToLocation(this, targets[Random.Range(0, targets.Count)]);
                    TrafficManager.RegisterCar(carCom);
                    RedSwitch = false;
                }
                else
                {
                    GameObject carObj = Instantiate(carPrefabs[1]);

                    Car carCom = carObj.GetComponent <Car>();
                    carCom.SetFromToLocation(this, targets[Random.Range(0, targets.Count)]);
                    TrafficManager.RegisterCar(carCom);
                }
            }
        }
        else
        {
            GameObject carObj = Instantiate(carPrefabs[Random.Range(0, carPrefabs.Length)]);

            Car carCom = carObj.GetComponent <Car>();
            carCom.SetFromToLocation(this, targets[Random.Range(0, targets.Count)]);
            TrafficManager.RegisterCar(carCom);
        }
    }