I use a coroutine to decrement a timer in my game. The timing is perfect when the game plays on the computer, but on the iPhone my timing is off. Here is my code:
//Decrements the timer by milliseconds
IEnumerator EnemyAttackTimer(float waitTime)
{
for (float i = 0; i < TimeBetweenAttacks;i+=.1f)
{
yield return new WaitForSeconds(waitTime);
attackTimerCountDown -= .10f;
//Adjust timer according to time between attacks
float temp = attackTimerCountDown / TimeBetweenAttacks * 1;
temp = 1-temp;
TimerObject.renderer.material.SetFloat("_Cutoff",temp);
}
}
The coroutine is called every .1 seconds and it decrements my variable attackTimerCountDown by .10 each time the coroutine starts. When the variable reaches 0, the attackTimerCountDown resets to TimeBetweenAttacks.
So if TimeBetweenAttacks was 10 seconds, my health bar would decrement every single millisecond. Again, this works great on the computer, but on the iphone it moves slower.
Help porfavor.