Method containing while loop in custom class?

Hi! After a lot of testing, I’m posting… Trying to implement nice clean classes for a music game, one of them is a “local tempo” class. But it seems the method containing a while loop is simply not responding (no errors, nada). I tried to strip it down to the following:

    class Test
    {
         var testInt :int;
         function Test()
         {
              testInt =0;
         }
         function TestNow()
         {
              while(testInt<100)
              {
                   testInt++;
                   yield WaitForFixedUpdate;
              }
         }
    }

then instantiating the class and calling its method:

var test:Test;
test =new Test;
test.TestNow();

Debugging test.testint just gives me 0 forever… Is it just not possible to execute a while loop in a method? Or am I missing something super obvious?

Many thanks for your help!

Gregzo

Yields and coroutines can only be defined in a class deriving from MonoBehaviour. So you have to make Test derive from MonoBehaviour and place that onto a GameObject.

But the while-loop should work fine if you get rid of the yield in your current script.