Created
March 27, 2014 17:16
-
-
Save jquave/9812904 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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