Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Finding the loop for me

Discussion in 'Scripting' started by masterbuilder335, Apr 8, 2021.

  1. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
    So what I would like to do is (Do something, wait, Do something, wait) and loop but I don't know which loop can do that
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    417
    use IEnumerator ;)
     
    masterbuilder335 likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    13,753
    As Terraya hints above, you want a Coroutine, which is an object returning an IEnumerator.

    Work through a few different tutorials for how to set them up and handle them. They're pretty powerful.
     
    Terraya and masterbuilder335 like this.
  4. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
    hmm, Will definitely take a look, Thx!
     
  5. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
    Code (CSharp):
    1.  IEnumerator HideStars()
    2.     {
    3.         yield return new WaitForSeconds(300);
    4.         StarsParticleSystem.Play;
    5.         yield return new WaitForSeconds(300);
    6.         StarsParticleSystem.Stop;
    7.     }
     
  6. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
    It says line 14 and 16 have a syntax error
     
  7. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
    Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
     
  8. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
    sorry 4 and 6
     
  9. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,040
    ()
     
    masterbuilder335 likes this.
  10. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
  11. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
  12. masterbuilder335

    masterbuilder335

    Joined:
    Jan 14, 2021
    Posts:
    55
    I got it, Thx!!
     
unityunity