Hello everyone!
A project on a smartphone in 2D, it is necessary that in a strictly limited time (2 minutes) the game object changes its position a specific number of times.
With a high FPS, everything goes smoothly, but if the FPS falls below 30, then the object does not have time to make the required number of position changes during this time.
The change of position is embedded in the coroutine, which is launched in Start (), then there is a cycle until the set time expires. There is an intersection with the function of changing the color of the object, which changes color depending on the number of positions passed.
How can you make sure that the number of position changes is always the same regardless of FPS?
DateTime timerEnd;
TimeSpan delta;
Text gameTimer;
void FixedUpdate()
{
Timer();
}
void Timer()
{
if (delta.TotalSeconds >= 0)
{
delta = timerEnd - DateTime.Now;
gameTimer.text = $"{delta.Minutes} : {delta.Seconds}";
}
if (delta.TotalSeconds <= 0)
{
playGame = false;
}
}
Tried to launch via Time.fixedDeltaTime
StartCoroutine(FlowerRespawn(TTLFlower * Time.fixedDeltaTime * 50));
Here is movement part
private IEnumerator FlowerRespawn(float timer)
{
if (playGame)
{
if (!flower.GetComponent<Image>().enabled) flower.GetComponent<Image>().enabled = true;
int rand = UnityEngine.Random.Range(0, pointPosition.Length);
flower.transform.position = pointPosition[rand].position;
if (nowPos == rand)
{
rand = UnityEngine.Random.Range(0, pointPosition.Length);
flower.transform.position = pointPosition[rand].position;
yield return new WaitForSeconds(0f);
}
nowPos = rand;
yield return new WaitForSeconds(timer * Time.fixedDeltaTime * 50);
Invoke("ColorChange", 0f);
}
}
So, the main problem is that in 2 minutes i need to show 180 objects with different colors and see if person will tap on it.
But sometimes, number of objects are changing )159, 171, 178 and so on. Not sure if it depends on the FPS, since i tested on the 12 pro max and 1mln% sure that my fps is high enough.