Syntax for calling a coroutine in C#?

I have written a simple coroutine in C#:

IEnumerator Loops() {
    while (someCondition) {
         DoSomething();
         yield return new WaitForSeconds(.1);
     }
}

I can’t find any examples - can WaitForSeconds take a float or does it do only whole seconds?

What is the calling syntax for this coroutine? The StartCoroutine(“Loops”) syntax used for Javascript doesn’t work.
Thanks![/code]

C# interprestes .1 as an double. To make it inteprete it as a float you have to stick an f after it. I.e: yield return new WaitForSeconds(.1f);

StartCoroutine(“Loops”); is the right syntax for starting a coroutine, if it doesn’t work there must be some other problem in your code.

Yes, WaitForSeconds can be of a float type.

I am not sure if this is getting to what you are looking to do but hopefully it helps shed some light on it for you.

using UnityEngine;
using System.Collections;

public class routineTest : MonoBehaviour {

	bool someCondition = true;
	
	// Use this for initialization
	void Start () {
		this.testStartRoutine();	
	}
	
	void testStartRoutine () {
	
		print ("COROUTINE START CALL");
		StartCoroutine("DoSomething");
		print ("COROUTINE DONE");
		
		
	}
	
	IEnumerator DoSomething(){
	
		print ("SOMETHING DONE");
       	yield return new WaitForSeconds(4.0f); 
		print ("SOMETHING DONE");
	
	}
	
}

Regards,

– Clint

Okay, thanks for the help, I’ve got it running now.

If I want to perform a task regularly, for example 30 times a second render the current frame of a quicktime movie to a texture, would it be a better approach to use coroutines or a timed routine?

WaitForSeconds is fine for that purpose.