Skip to content

Instantly share code, notes, and snippets.

@jquave
Created March 27, 2014 17:16
Show Gist options
  • Select an option

  • Save jquave/9812904 to your computer and use it in GitHub Desktop.

Select an option

Save jquave/9812904 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using System.Timers;
public class JQTimer {
public bool running = true;
System.Action action;
Timer timer;
public JQTimer(System.Action _action) {
action = _action;
}
void RunEveryNSeconds(float seconds) {
timer = new Timer(seconds);
timer.Elapsed += new ElapsedEventHandler(HandleEveryNElapsed);
timer.AutoReset = true;
timer.Enabled = true;
}
void HandleEveryNElapsed (object sender, ElapsedEventArgs e) {
Debug.Log("asf: "+sender+":"+e);
action();
}
// Public methods
public static void EveryNSeconds(float seconds, System.Action action) {
JQTimer t = new JQTimer(action);
t.RunEveryNSeconds(seconds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment