void SpawnTruck() { if (_initialDeliveryTruckDelay >= 0) { _initialDeliveryTruckDelay -= Time.deltaTime; } else { _deliveryTruckSpawnTimer -= Time.deltaTime; if (_deliveryTruckSpawnTimer <= 0.0f) { if (_currDeliveryTrucks < _realMaxDeliveryTrucks) { Truck t = DeliveryTruckSlots[Random.Range(0, DeliveryTruckSlots.Length)].GetComponentInChildren <Truck>(); t.IsDeliveryTruck = true; while (!t.IsOffscreen) { t = DeliveryTruckSlots[Random.Range(0, DeliveryTruckSlots.Length)].GetComponentInChildren <Truck>(); t.IsDeliveryTruck = true; } t.InitialWaitTime = _deliveryTruckWaitTime; t.Arrive(); _currDeliveryTrucks++; _deliveryTruckSpawnTimer = Random.Range(_deliveryTruckSpawnDelay / 2.0f, _deliveryTruckSpawnDelay); ; } } } if (_initialPickupTruckDelay >= 0) { _initialPickupTruckDelay -= Time.deltaTime; } else { _pickupTruckSpawnTimer -= Time.deltaTime; if (_pickupTruckSpawnTimer <= 0.0f) { if (_currPickupTrucks < _realMaxPickupTrucks) { Truck t = PickupTruckSlots[Random.Range(0, PickupTruckSlots.Length)].GetComponentInChildren <Truck>(); t.IsDeliveryTruck = false; while (!t.IsOffscreen) { t = PickupTruckSlots[Random.Range(0, PickupTruckSlots.Length)].GetComponentInChildren <Truck>(); t.IsDeliveryTruck = false; } t.InitialWaitTime = _pickupTruckWaitTime; t.Arrive(); _currPickupTrucks++; _pickupTruckSpawnTimer = Random.Range(_pickupTruckSpawnDelay / 2.0f, _pickupTruckSpawnDelay);; } } } }