Coroutine and Loops

Hi there, I’m using coroutines to drive a character behaviour:

	void Start ()
	{
		m_rigidbody = GetComponent<Rigidbody2D> ();
		m_characterProperties = GetComponent<CharacterProperties> ();
		 
		StartCoroutine (StartBehaviour ());

	}

	IEnumerator StartBehaviour ()
	{

		m_timer = 0f;
 
			while (m_timer < 2.0f) {
				m_timer += Time.deltaTime;
				yield return null;
			}
			StartCoroutine (Check ());

	}

So in the above example, I wait two seconds then call the Check() coroutine (not shown for clarity) - this all works fine. However, I basically want to loop this behaviour - so I want the logic to repeat (so wait two seconds, then call Check again, repeat). However, I’m a little lost how to best do this - any suggestions? Thanks!

If you dont want to stick to coroutine then follwoing will work.
Wait for 2 seconds and call Check func , followed by repeated call every 2 seconds.

InvokeRepeating("Check", 2,2);

Here’s a heavy-handed way of approaching it:

IEnumerator StartBehaviour ()
{
    while(true) {
         m_timer = 0f;
 
         while (m_timer < 2.0f) {
             m_timer += Time.deltaTime;
             yield return null;
         }
         StartCoroutine (Check ());
         m_timer = 0.0f;
         yield return null;
     }

}

That way, the “StartBehaviour” Coroutine continues endlessly and the timer resets every time it’s successful.