So throughout this course, we've talked a lot about Unity events, right?
But we've never made our own.
We've only really used the pre-existing ones and had them do things.
But in this video, we're going to define a Unity event for when this game is won,
and then we can decide in the editor what we want to happen when the user wins.
So we'll make a public Unity event,
and we can see that even though we're typing in Unity event,
it doesn't seem to be recognized as the type we need it to be, right?
That's because some things aren't included in this basic Unity engine namespace up here.
We want to import UnityEngine.Events, just like that.
And now we have access to the Unity event class.
Perfect.
So we'll make a public Unity event, and we can call this game is won.
Just like that.
That's all we really have to do.
But we also have to invoke this Unity event, so it'll actually happen at a specified time.
Right now, when the order is correct, we run this open box method, right?
Well, let's forget about opening the box for now in this script.
Of course, we could continue to do this through code,
but I just want to show you how we can do this in the editor as well with our own custom Unity event.
So we'll delete this and let's rename our open box method,
and we can call this complete game.
So it's just a little bit more generic.
And now, instead of doing something in particular, instead of opening that box through a defined line of code,
all we have to do is talk to our Unity event that we've made.
Our game is won, and we say game is won.invoke, just like that.
And this invoke method invokes all registered callbacks.
So all of the things that we add to our Unity event, those will all occur.
They'll all happen when we invoke this Unity event.
With surprisingly little change to our code, we can now go back into the editor.
On our box, we now have our own Unity event called game is won.
And we can make it do stuff, just like any other Unity event.
So we can have it talk to our lid,
and we can talk to the lid's animator and have it set a trigger.
And, wow, what was that called again?
It was called open, just wanted to double check.
We can have an animator set trigger open, just like we did in code.
And we can have it enable our WinText.
And, you know, we can also do whatever we want.
So we'll enable this.
And you know the power of this is now in the editor without having to modify our script,
we can have a bunch of different things happen when the game is won.
Of course, we could have also done this through code.
Maybe you prefer doing that, but maybe you prefer doing it this way.
Really, the choice is up to you.
I just want to show you how you can make your own Unity event,
because I think they're really cool.
All right, let's test this out.