Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question My wait for seconds timer is not waiting

Discussion in 'Scripting' started by baconpie108, May 10, 2024.

  1. baconpie108


    Mar 7, 2024
    I'm trying to run this timer, and I'm pretty sure that I have the syntax correct but it doesn't seem to be waiting.

    Here is the code for the call of the coroutine (these are in the same monobehavour script)
    Code (CSharp):
    1. if (swayPosition > twoPI)
    2. {
    3.     swayDirection = !swayDirection;
    4.     swayPosition -= twoPI;
    5.     StartCoroutine(PauseSway());
    6. }
    And here is the code for the PauseSway method
    Code (CSharp):
    1.     public IEnumerator PauseSway()
    2.     {
    3.         if (!swayPaused)
    4.         {
    5.             swayPaused = true;
    6.             UnityEngine.Debug.Log("started");
    7.             yield return new WaitForSeconds(swayPause);
    8.             UnityEngine.Debug.Log("ended");
    9.             swayPaused = false;
    10.         }
    11.     }
    The two things added to the console happen at the same exact time no matter how many seconds I put in for WaitForSeconds. IE: if swayPayse is 3, the console says started and ended both happen on the same second
  2. baconpie108


    Mar 7, 2024
    Nvm, figured it out immedietly, turns out I had swayPosition default as 3 but the game object that uses it had it set to less than a second.

    God I am stupid.

    Although I would like to know how I mark a thread as resolved, or am I confusing this with steam forums?
    Bunny83 likes this.
  3. Bunny83


    Oct 18, 2010
    No, you're not stupid. You do programming and you develop games, certainly not stupid :) Just an ordinary oversight, happens to everyone every now and then.

    Well, the forum isn't really a classical Q&A site. Though some add a tag "resolved" to the thread. But there's not really a functionality built-in
    orionsyndrome likes this.