Game Development Reference
In-Depth Information
method in the script when the event occurs. As stated before, this just logs in to the Con-
sole window for now so that we have something to see.
Just for fun, also add this script to one or both of the borders in our scene; this is simply
because we don't have anything else at the moment. You could add it to the player, making
the event as an alarm that goes off and changing the ThePlayerIsTryingToLeave
method to cause the player to run in the opposite direction if you wish.
If you run the project now, you should get the following results:
• One message to tell you that the MessagingManager script has started.
• One message per subscriber that has registered with the manager (although in the
Console window, you may just see 2 next to the event because it is the same).
• When the event is triggered, you will get one message per subscriber to tell you
that they have received it. Note that each message from the client is particular to
the game object you attached it to as the message is different.
Now, you could have just executed the preceding code using the Send or Broadcast
Unity methods, and it would have been much simpler. However, you should note that
since we are using a single manager class, which is a static instance in the scene, at no
point should any of the game objects involved need to know about each other. There is no
need to search the hierarchy or add components to each other at editing time; it just works.
Search WWH ::




Custom Search