I recently discovered Unity and immediately got interested. It seems to be a very good product, but I’m having some problems “thinking in Unity”. I’ll explain a few examples, and hopefully someone with some spare time and a kind heart have the time to answer them. Oh and I don’t necessarily need any code but just the general approach.
I am used to the idea of having a single game loop. Where is the current loop? Will each objects Update function be an entry in that loop? How can I change their order? (calculate GameObject A before B for instance)
How would I go about creating an overall Timer that keeps track of certain conditions as well as runs a countdown? For instance: I want enemies in my game to attack in timed waves. Do I just create an object, call it timer, place it in the game and have it do its job…? Or…?
I’m pretty new also but i’ll help with what I can.
The Update() function is called every ‘loop’, it’s added into the ‘loop’ automatically so you don’t have to worry about it. If you want to prioritize updates you cal call LateUpdate() and that will be called after all of the Update() functions have been called. Check out this link for other bits and pieces you might find useful in regards to updates: http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.html
The game loop is implemented inside Unity itself. You don’t interact with it directly. You also don’t have a way of ordering calls to Update(); all Unity guarantees is that Update() will be called once per frame on every active MonoBehaviour. If you need control over update order between objects/scripts, you’ll need to have a single ‘manager’ script with an Update() that calls a different function on earch of the other objects/scripts in the appropriate order.
Sure, you could have a general ‘timer’ object… it depends on what exactly you want to do. It may be easier to use different timers for triggering behaviours with different periods/frequencies. Do whichever makes the most sense to you and to the game logic you want to implement.