// Use this for initialization void Start() { myFlock = this; goalPos = this.transform.position; /*camera fog * renderSetting.fogColor=Camera.main.backgroundColor; * renderSetting.fogDensity=0.03f; * RenderSetting.fog=true;**/ //goalPos = transform.position; for (int i = 0; i < numFish; i++) { Vector3 pos = new Vector3(Random.Range(-swimLimits.x, swimLimits.x), Random.Range(-swimLimits.y, swimLimits.y), Random.Range(-swimLimits.z, swimLimits.z)); allFish[i] = (GameObject)Instantiate(fishPrefab, pos, Quaternion.identity); } }
void Update() { if (passParametersToFlock) { foreach (Transform child in transform) { FlockingFish f = child.gameObject.GetComponent(typeof(FlockingFish)) as FlockingFish; f.parameters = parameters; } } if (Random.Range(0, 1000) < 5) { //generateSeekPosition(); } foreach (Transform child in transform) { child.localScale = new Vector3(fishScale, fishScale, fishScale); } if (fishScale < maxScale && Input.GetKey("up")) { fishScale += 1f; } if (fishScale > minScale && Input.GetKey("down")) { fishScale -= 1f; } List <GameObject> allFish = getAllFish(); //Unique list for each breed. List <GameObject>[] fishByBreed = new List <GameObject> [10]; for (int i = 0; i < fishByBreed.Length; i++) { fishByBreed[i] = new List <GameObject>(); } //This will hold all the alive populations for each breed. int[] fishCountByBreed = new int[10]; for (int i = 0; i < fishCountByBreed.Length; i++) { fishCountByBreed[i] = -1; } //Setting a temp value for now, seems to give some bugs otherwise once in a while. foreach (GameObject fish in allFish) { if (fish.GetComponent <FlockingFish>().dying == false) { int index = fish.GetComponent <FlockingFish>().GetBreed(); fishByBreed[index].Add(fish.gameObject); } } for (int i = 0; i < fishByBreed.Length; i++) { fishCountByBreed[i] = fishByBreed[i].Count; // Debug.Log("Number of fishes for breed " + i + " is: " + fishCountByBreed[i]); } //Go through each now. Sigh. I hate array of arrays. :| for (int i = 0; i < fishCountByBreed.Length; i++) { if (fishCountByBreed[i] > populationIndexes[i].minPopulation) { GameObject oldestFish = findOldest(fishByBreed[i]); if (oldestFish != null) { if (oldestFish.GetComponent <FlockingFish>().age > oldAge) { oldestFish.GetComponent <FlockingFish>().dying = true; } } } if (fishCountByBreed[i] > populationIndexes[i].maxPopulation) { GameObject oldestFish = findOldest(fishByBreed[i]); if (oldestFish != null) { oldestFish.GetComponent <FlockingFish>().dying = true; } } } }