var canGo = true;
var canStop = false;
var counter = 0;
function Start(){
canGo = true;
stopit();
}
function Update () {
if(canGo){
StartCoroutine("DoSomething", counter); // Call coroutine from update!
canGo = false;
}
if(canStop){
StopCoroutine("DoSomething"); // Stop coroutine from update!
canStop = false;
Start();
}
}
function DoSomething (count : int) {
counter ++;
Debug.Log("I started! - " + count);
yield WaitForSeconds(5);
Debug.Log("Can't stop me! - " + count);
}
function stopit(){
yield WaitForSeconds(2);
canStop = true;
}