Timer For Occasional Action

I've done some searching, and have found a few examples that KIND OF touch on what I'm looking to do, but I'm getting some odd behavior.

I'm looking to create a timer that will execute a block of code every, say, 5 minutes. My thought was to use "VALUE % INTERVAL" and if the value was 0, execute the code.

In a short test, however, I'm getting something...unusual (C#):

void Update()
{
    float count = Mathf.Floor(Time.time % 10.0f);
    if (count == 0)
    {
         print("OK!");
    }
}

I figure that in this case, a simple Time.time mod 10 would eventually tick over to 0, then would start again as Time.time continued on it's way. The Mathf.Floor() is there because otherwise, a modulus operation could return 0.1, 0.2, 0.5, etc, when all I want is 0.

However, when simply debugging the Mathf.Floor(Time.time % 10.0f), the output window counts to 9...and then stops. It doesn't flip over or anything.

I've looked at other timer methods mentioned around here, but none seem to work for what I'm looking to do. I noticed one, written in JS, but when I attempted to translate to C# for my purposes, didn't fit the bill.

Any suggestions?

Thanks! Chris

My suggestion would be to use Invoke or InvokeRepeating and set the time to however long you want.

void Start () {
    InvokeRepeating("SayHello", 0, 10);
}

void SayHello () {
    print("Ok");
}

Peter's solution is best, InvokeRepeating will do exactly what you want. But to address your counting code not work (since I already ran a test :) , I suspect it's a typo in your code. I did this:

public float count;
void Update () {
    count = Mathf.Floor(Time.time % 10.0f);
}

And it worked as expected. Looking at it in the Inspector, count went from 1,2,3...9,0,1,2,3...