Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Run Loop every second with Visual Scripting

Discussion in 'Visual Scripting' started by lechatpinouf, Oct 30, 2023.

  1. lechatpinouf

    lechatpinouf

    Joined:
    Oct 24, 2023
    Posts:
    2
    Hi,
    I'm trying to run some code every second, not every frame, but I'm unsure how to.
    Any help is appreciated, thank you.
     
  2. lechatpinouf

    lechatpinouf

    Joined:
    Oct 24, 2023
    Posts:
    2
    Using a If and Cooldown component works actually, just set the duration and plug in completed to what you wanna run every second, and make the condition what you want, or something that'll never solve itself if you want it to run forever, and badabim badaboom.
    Anyway have a good day.
     
  3. termway

    termway

    Joined:
    Jul 5, 2012
    Posts:
    80
    An alternative way to do it is to use a loop with a WaitForSeconds unit.

    upload_2023-11-2_16-35-1.png

    That would be the equivalent of this C# code.

    Code (CSharp):
    1.  IEnumerator Start()
    2.         {
    3.             while (true)
    4.             {
    5.                 yield return new WaitForSeconds(1f);
    6.                 Debug.Log("every 1s");
    7.             }
    8.         }