again, to get an even better object oriented design.
make it so that none of the game objects need to know about each other at all.
Let's go see how we can make that happen.
Okay, this is the game that we ended with in the previous lecture.
but better than the fish knowing about the HUD.
by implementing what I'll call a utility class.
It's a class that provides helpful functionality to objects in the game.
using in the wacky breakout project.
Just a reminder of the way this currently works.
then adds its AddPoint method as a listener for the point added event.
that lets listeners like the HUD, add event listeners for the event.
this is not a child class of MonoBehavior, so I'll get rid of that.
the fish will actually both end up calling methods on the EventManager.
we can just make this a static class instead.
since we're not a child class of moto behavior.
I'm going to implement two fields in this EventManager class.
and I'm going to add a field that holds the listener for the event.
So both of these fields will be static so they're accessible within static methods.
I'll call this the invoker.
a UnityAction<int> and I'll call that listener.
Now, I immediately get a compilation error because I need a using directive.
Now I'm going to add two static methods.
And this is going to be a Fish script.
I will say that invoker, = script.
the Fish object and find the Fish script.
The HUD doesn't have to go looking for that object and find the Fish script.
The fish knows about its own script.
it can add itself as an invoker in the EventManager.
add self as event invoker.
and that is this instance of the Fish class.
to know which order these game objects get added to the game.
We're not going to have to care if the HUD gets added first.
on the fish, that fish isn't in the game yet, so we'll have a problem.
or the listener is added first here in the EventManager.
if a listener has been added, we will add it as a listener on this invoker.
it's been sitting around waiting to get added to an invoker.
Now that we're adding the invoker, we can add that listener to it.
We want to make sure we're only doing that if listener isn't null.
That's how we can tell whether a listener has already been added.
then we will say invoker.AddPointsAddedEventListenter.
The add listener method is similar.
I'll type it in and then we'll come back.
We're going to pass in our event handler as the listener.
then we check to see if the invoker isn't null.
if it's not null, then we'll call the method to add the listener for that event.
the fish doesn't have to know about the HUD.
if you will, to handle all those details.
We've already had the fish, add itself as an invoker.
we can get rid of this stuff.
All we have to say is EventManager.AddListener(AddPoints).
I'll run to show that everything still works properly.
you can see that the score gets added properly.
as the invoker and listener, respectively but that's okay.
that's what we've implemented here.
of the game objects need to know about each other to implement our event system.
And this leads to a really solid object oriented design.