void MeteorSpawn() { if (currentConfig.duration < 0 && meteorConfigs.Count > 0) { currentConfig = null; return; } currentConfig.duration -= 1; System.Random random = new System.Random(); if (random.NextDouble() < currentConfig.probability) { GameObject meteor = Instantiate(meteorPrefab) as GameObject; GameObject[] tiles = GameObject.FindGameObjectsWithTag("tile"); int index = new System.Random().Next(0, tiles.Length); meteor.GetComponent <Meteor>().SetDestination(tiles[index].GetComponent <Tile>()); Meteor meteorScript = meteor.GetComponent <Meteor>(); meteorScript.toStartFire = Random.value < currentConfig.fireProbability; meteorScript.toDestroy = Random.value < currentConfig.destroyProbability; currentConfig.duration -= currentConfig.cooldown; Invoke("MeteorSpawn", currentConfig.cooldown); return; } Invoke("MeteorSpawn", 1); }
public MeteorConfig(MeteorConfig previousConfig) { Destructive = previousConfig.Destructive; MinimumMinutesBetweenMeteorSpawns = previousConfig.MinimumMinutesBetweenMeteorSpawns; MaximumMinutesBetweenMeteorSpawns = previousConfig.MaximumMinutesBetweenMeteorSpawns; MinimumSpawnDistanceInChunks = previousConfig.MinimumSpawnDistanceInChunks; MaximumSpawnDistanceInChunks = previousConfig.MaximumSpawnDistanceInChunks; MinimumMeteorLifespanInSeconds = previousConfig.MinimumMeteorLifespanInSeconds; MaximumMeteorLifespanInSeconds = previousConfig.MaximumMeteorLifespanInSeconds; }
public void AddConfig(int duration, float probability, int cooldown, float fireProbability, float destroyProbability) { MeteorConfig config = new MeteorConfig(); config.cooldown = cooldown; config.duration = duration; config.probability = probability; config.fireProbability = fireProbability; config.destroyProbability = destroyProbability; meteorConfigs.Enqueue(config); }
// Update is called once per frame void Update() { if (currentConfig == null && meteorConfigs.Count == 0) { return; } if (currentConfig == null) { currentConfig = meteorConfigs.Dequeue(); Invoke("MeteorSpawn", 1); } }
private IEnumerator SpawnMeteor(MeteorConfig meteorConfig) { //for (int meteorCount = 0; meteorCount < meteorConfig.GetNumberOfMeteors(); meteorCount++) //{ var newMeteor = Instantiate( meteorConfig.GetMeteorPrefab(), meteorConfig.GetWaypoints()[0].transform.position, Quaternion.identity ); newMeteor.GetComponent <MetorSpot>().SetWaveConfig(meteorConfig); yield return(new WaitForSeconds(meteorConfig.GetTimeBetweenSpawns())); //} }
public void SetWaveConfig(MeteorConfig meteorConfig) { this.meteorConfig = meteorConfig; }