private void GenerateCar() { var carPrefab = AvailableCarPrefabs.GetRandomElement(); var spawnPos = GenerateAtPoints.GetRandomElement(); // Select random far point var points = Waypoints .Where(x => x.IsFinish && Vector3.Distance(transform.position, x.transform.position) > 20f); if (points.Count() == 0) { throw new System.Exception("Not found far points"); } var point = points.GetRandomElement(); var car = Instantiate(carPrefab, spawnPos.position, spawnPos.rotation).GetComponent <CarMovement>(); car.SetMinMaxWaitTime(MinCarWaitTime, MaxCarWaitTime); car.SetDestination(point.transform.position); car.SetSpeedMultiply(SpeedMultily); }