Just a bit confused as to why this is happening: I have a coroutine that does a simple animation where it takes a starting number and an ending number and shifts the starting number to the ending number in a text object. I have this script on its own object specifically for this purpose and that object is a prefab that remains unchanged between scenes. It works perfectly fine when in the scene I designed it in as well as an additional scene, but I just recently put it in a different scene without changing anything and it runs very slow comparatively. Something like 2-3 times as slow. Does anyone know why this is happening and how to fix it?
Here is the coroutine:
IEnumerator transitionValue(int startAmount, int endAmount)
{
int difference = 0;
int trackVal = startAmount;
int changeAmount = 1;
ended = false;
currencyText.text = $"{startAmount:n0}";
if (startAmount > endAmount)
{
downOrUp = true;
difference = startAmount - endAmount;
}
else if (startAmount < endAmount)
{
downOrUp = false;
difference = endAmount - startAmount;
}
float timeBetweenRuns = 0.1f/difference;
if (difference > 500)
{
changeAmount = 2;
}
else if (difference > 1000)
{
changeAmount = 3;
}
else if (difference > 3000)
{
changeAmount = 4;
}
else if (difference > 10000)
{
changeAmount = 5;
}
else if (difference > 20000)
{
changeAmount = 10;
}
while (!ended)
{
if (trackVal == endAmount)
{
ended = true;
break;
}
if (downOrUp)
{
trackVal -= changeAmount;
}
else
{
trackVal += changeAmount;
}
currencyText.text = $"{trackVal:n0}";
yield return new WaitForSeconds(timeBetweenRuns);
}
if (!downOrUp)
{
foreach (string[] stat in data.stats)
{
if (stat[0] == data.currentUser && stat[1] == "Bonepoints")
{
stat[2] = "" + endAmount;
}
}
}
currentBonePoints = endAmount;
}