/// <summary> /// Function to spawn the trucks. /// </summary> private void ProcessTrucks() { // 1000ms -> 1 second * 60 == 1 minute. double truckSpawnInterval = (1000 * 60) / truckRate; double truckSpawnDelta = gameTimeInMs - lastTruckSpawn; //Check if we can spawn a new truck. if (truckSpawnDelta >= truckSpawnInterval) { //Make and get the truck (id). ushort truckId = world.AddEntity <Truck>(data.TruckSpawnpoint, data.TruckSpawnpointRotation); //Tell the truck to drive to the loading bay. Truck truck = world.GetEntity <Truck>(truckId); truck.TaskDriveTo(data.Loadingbay, 0.33f); //Store and reset last spawned truck. trucks.Add(truckId); lastTruckSpawn = gameTimeInMs; } //Update all the trucks. foreach (ushort truckId in trucks) { Truck truck = world.GetEntity <Truck>(truckId); truck.Tick(); world.UpdateEntity(truck); } }