Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Loading bar speed changing on phone

Discussion in 'Scripting' started by ciadyuge, Sep 13, 2023.

  1. ciadyuge

    ciadyuge

    Joined:
    Jan 29, 2014
    Posts:
    12
    I try to make a bar with loop in IEnumerator. This works fine on my pc, but when i build apk and run it at my phone loop is working more slowly than my pc. What should i do? (i tried while and for loop, all of them gave same result)

    Code (CSharp):
    1.   while (valueCurrent < currentValue)
    2.                {
    3.                 valueCurrent = valueCurrent + 1;
    4.                 ValueText.text = valueCurrent.ToString();
    5.                 }
    6.  
    7.                 yield return null;
    8.             }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    I suppose you could buy a slower PC, or else buy a faster phone? :)

    You have written frame-counting code. That's most likely the source of your discrepancies.

    If you want consistent timing, traditionally one works in time (usually seconds) and advances time this way:

    Code (csharp):
    1. elapsedTime += Time.deltaTime;
    where
    elapsedTime
    is a float
     
    Yoreki likes this.