// Update is called once per frame void Update() { float distance; // Check for bunnies in love, and create couples if they are close enough _bunniesInLove.RemoveAll(i => !i.bunnyState.Equals(Bunny.State.InLove)); if (_bunniesInLove.Count > 1) { Bunny bunny1 = _bunniesInLove[Random.Range(0, _bunniesInLove.Count - 1)]; for (int i = 0; i < _bunniesInLove.Count; i++) { if (_bunniesInLove[i] != bunny1) { distance = Vector3.Distance(bunny1.transform.position, _bunniesInLove[i].transform.position); if (distance <= distanceToFallInlove && bunny1.bunnyGender != _bunniesInLove[i].bunnyGender) { if (!couples.Exists(ibunny => ibunny.bunny1 == bunny1 || ibunny.bunny2 == bunny1)) { CreateCouple(bunny1, _bunniesInLove[i]); } break; } } } } //Check for couples to mate for (int icouple = 0; icouple < couples.Count; icouple++) { Couple couple = couples[icouple]; if (couple.AnyIdle() && !couple.doneFeed) { couple.SendToFeed(); } if (couple.AllInFeed() || couple.doneFeed) { if (!couple.doneFeed) { couple.timeInFeed += Time.deltaTime; if (couple.timeInFeed >= timeInFeed) { couple.doneFeed = true; couple.maleChance = couple.GetMediumCarrotValue(); couple.Male.GoIdle(); } } couple.timeFemaleInFeed += Time.deltaTime; if (couple.timeFemaleInFeed >= timeFemaleInFeed) { _bunniesToBorn = Random.Range(2, 5); for (int ibunny = 0; ibunny < _bunniesToBorn; ibunny++) { AddBunny(_gameManager.feedSpot.position, 1, couple.maleChance); } couple.Female.GoIdle(); _couplesDone.Enqueue(icouple); } } } while (_couplesDone.Count > 0) { couples.RemoveAt(_couplesDone.Dequeue()); } }