Event listening in programming is very interesting, and there are many different approaches. The way Unity does it is less event listening, and MORE event describing.
The class MonoBehaviour all ready HAS An Update() function for example, which it calls over and over and over again. When you define Update() in your script, (Which is a MonoBehaviour subclass), YOUR Update() starts getting called by the MonoBehaviour class, through the concept of method overriding. If you have ever dabbled in Java, then this is very similar to the run() method associated with the Runnable interface!
All of the functions that are available to MonoBehaviour in that form, are in fact allready defined as empty methods. They still get called as usual, but they just don't do anything in response :) By putting it in your code, you are basically, "filling in the blanks". You make those functions actually do something, rather than doing nothing.
This differs from event handling, where you assign one (or more) callbacks to an event, and the event server iterates though those and calls them. IN Unity, Unity is iterating through all monobehaviours and calling their all ready defined methods. You jsut overload those methods.
(If you want to learn more about this concept, this page is all about it: [http://www.akadia.com/services/dotnet_polymorphism.html][1])
[1]: http://www.akadia.com/services/dotnet_polymorphism.html
↧