I have a list of harvested crops. There's a capacity of let's say 100 crops(100 items in a list). Now I want to empty the list within X seconds when max full (2 sec in my case). This should be relative to the max cap. If the list is 100 it should take 2 sec if 50 then 1 sec accordingly. What should be the approach for achieving that?
The reason for this is that I want to iterate over each crop item and animate them towards some point for selling. I have tried for loop but it's not quite giving me the right time as my max cap changes over time when the user upgrades but I want the animation time to be constant to 2 sec when the list is maxed up.
This is what I tried:
private IEnumerator MoveHarvestToStore()
{
float startTime = Time.time;
animationTimeForSelling = 2.0f * trunkCapacityFilled / trunkTotalCapacity;
Debug.Log("Anim Time = " + animationTimeForSelling);
for (int i = pickablesInHarvester.Count - 1; i >= 0; i--)
{
float animTime = animationTimeForSelling / pickablesInHarvester.Count;
yield return new WaitForSeconds(animTime);
}
float endTime = Time.time;
Debug.Log("Time took = " + (endTime - startTime));
}
The problem with the above code is that this is not consistent in terms of time. Following are the logs with the same trunkCapacityFilled and trunkTotalCapacity every time:
Anim Time = 2, Time took = 2.17
Anim Time = 2, Time took = 2.15
Anim Time = 2, Time took = 2.16
Anim Time = 2, Time took = 2.213
Anim Time = 2, Time took = 2.13