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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can someone help me with this code?

Discussion in 'Scripting' started by Venatal, Dec 3, 2015.

  1. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    Code (CSharp):
    1.  
    2. IEnumerator SquareSpawn()
    3.     {
    4.         while (true)
    5.             for (int i = 0; i < 4; i++)
    6.             {
    7.                // Do Stuff
    8.  
    9.                 if (DoubleSpawn1().isActive)
    10.                 {
    11.                     yield return new WaitForSeconds(0.3f);
    12.                 }
    13.             }
    14.     }
    15.  
    16.     public void DoubleSpawn1()
    17.     {
    18.         // Do Stuff
    19.     }
    20.  
    What I'm trying to do is pause SquareSpawn() for 0.3 seconds, but I can't figure it out and I just get an error with "if(DoubleSpawn1().isActive)"
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    duplicate threads generally aren't the way to go...

    this looks like a very "odd" approach, especially the "forever loop for 0-4"... what are you trying to do (and don't just say "I want to pause for 0.3 seconds... "
     
  3. Kamilche_

    Kamilche_

    Joined:
    Jan 11, 2015
    Posts:
    75
    Something like this is more in order:

    Code (CSharp):
    1.  
    2.             bool somethingInteresting = true;
    3.             if (somethingInteresting)
    4.             {
    5.                 yield return new WaitForSeconds(0.3f);
    6.             }
    7.  
     
    Venatal likes this.
  4. Venatal

    Venatal

    Joined:
    Nov 12, 2015
    Posts:
    134
    That worked perfectly, thanks a lot man!