Thanks for any help you’re able to give in advance.
I have a GameObject which is directing traffic in my game. Every X seconds I want it to make the decisions for what will happen over the next 10 seconds and tell all of the other objects what to do. For the purpose of this, I have:
Timer t = new Timer(10000);
void Start () {t.AutoReset = true;
t.Elapsed += new System.Timers.ElapsedEventHandler(GameTick);
t.Start();
Debug.Log("Timer started.");
return;
}
In Visual Studio Timer resolves to System.Timers.Timer correctly. The timer itself works beautifully.
The problem is that I keep coming across warnings and failures resulting from attempting to access information apart from the ‘main thread’. You can’t access transform.position for any object outside of the ‘main thread’, for example. On the main object in question, I’ve gotten around this by storing the transform.position in a variable every FixedUpdate().
But now I find that you can’t even GetComponent scripts from another object, which means I can’t trigger certain behaviors.
TLDR
I’m using System.Timers.Timer to make decisions on a fixed interval, but the resulting multitasking prevents me from accessing information in any simple way. I either need a way to access this information, or a means of creating a reliable timer without multi-threading.