Hello,
I make an RPG with turn based combat where the turn ordere is calculated based on the character speed.
A Coroutine checks if a character is ready. If no character is ready it increases all characters Action Progress bar by a value ( different for each char) and starts the coroutine again as long as no character is ready for action. My Problem is now that i wanted to test it and every time i start the play mode, the action bars recharge at a different speed. I think its because of framerate and other stuff going on. but this will be a problem with different devices as some people will wait longer than other. Tried to solve this with Time.deltaTime but its not exactly working. Can someone have a look on my Code?
IEnumerator WaitForCharactersReady()
{
float tickTime = 0.02f;
if (readyCharacters.Count == 0)
{
for (int i = 0; i < playerTeamControllers.Length; i++)
{
playerTeamControllers*.characterStats.IncreaseActionProgressByOneTick();*
playerSpotUis_.SetActionBar((int)playerTeamControllers*.characterStats.actionProgress);_
_if (playerTeamControllers.characterStats.isReadyForAction())
{_
_readyCharacters.Add(enemyTeamControllers);
}*_
}
for (int i = 0; i < enemyTeamControllers.Length; i++)
{
enemyTeamControllers*.characterStats.IncreaseActionProgressByOneTick();*
enemySpotUis_.SetActionBar((int)enemyTeamControllers*.characterStats.actionProgress);_
_if (enemyTeamControllers.characterStats.isReadyForAction())
{_
_readyCharacters.Add(enemyTeamControllers);
}
}
while(tickTime >= 0.0f)
{*
tickTime -= Time.deltaTime;
yield return null;_
}
StartCoroutine(WaitForCharactersReady());
}
}