protected IEnumerator FindFlowersOverTime() { //give ourselves a second before looking for a flower double waitUntil = WorldClock.AdjustedRealTime + 1f; while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed) { yield return(null); } while (!mDestroyed) { while (RestingOnFlower) { //don't get a flower we're not resting on yield return(null); } while (WorldClock.AdjustedRealTime < StartleTimeEnd) { yield return(null); } while (CurrentFlower == null) { //find something between the player and the critter, closer if it's friendlier if (Plants.Get.NearestFloweringPlant(Player.Local.Position, 5f, LastFlower, ref CurrentFlower)) //, mCurrentPosition, Friendly ? 0.1f : 0.8f), 4f, LastFlower, ref CurrentFlower)) { { mCurrentFlowerPosition = CurrentFlower.worlditem.Position; mRandomFlowerPosition = CurrentFlower.GetRandomFlowerPosition(); //wait by default, we'll find out if we can occupy it later WaitingForFlower = true; mMaxWaitTime = WorldClock.AdjustedRealTime + (RestOnFlowerTime * 2); } else { waitUntil = WorldClock.AdjustedRealTime + 0.5f; while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed) { yield return(null); } } } while (WaitingForFlower) { if (CurrentFlowerHasMoved) { //whoops, we'll have to start over again CurrentFlower = null; WaitingForFlower = false; yield return(null); } else { //see if it's occupied if (!CurrentFlower.IsOccupied) { CurrentFlower.OccupyingCritter = this; WaitingForFlower = false; yield return(null); } else { if (WorldClock.AdjustedRealTime > mMaxWaitTime) { WaitingForFlower = false; CurrentFlower = null; } else { waitUntil = WorldClock.AdjustedRealTime + (Random.value * 0.5f) + 0.1f; while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed) { yield return(null); } } } } } waitUntil = WorldClock.AdjustedRealTime + 0.5f; while (WorldClock.AdjustedRealTime < waitUntil && !mDestroyed) { yield return(null); } yield return(null); } }