Letting every object (if it wants it) know that sth happened?

Hello,

I’m learning game programming in Unity and I’m making a simplified The Binding Of Isaac clone (a rogue-like).

When I kill the last enemy in the room I want many things to happen. I can do it by accessing a script attached to a GameManager object and checking if (enemiesLeftScript.enemiesLeft == 0).

I was just wondering if there’s an option to do something like this: “Manager sees that the last enemy just got killed! He sends a ‘message’ that any object can ‘catch’ and do something then, e.g. spawn doors out of the room, spawn a reward for clearing a room, etc.

It would basically do what I can already do with the if statement paraphrased above, but if it worked somewhat like I described it, it might be a more convenient choice. So…

Does something, like the thing I described, exist?

Cheers!

PS If you’re not sure you understood what I meant, let me know! English isn’t my first language :wink:

I think robertbu’s comment answers your question.

Though I’ve made a roguelike game before and imo having a central “authority” gamemanager gameobject is a better way to go architecture-wise.

So you have your gamemanager gameobject. And it has one or more script components that manage and keep track of the various aspects of your game. (If you have more than one, then have a “master” one that contains references to all the others)
You give your other scripts (like monster player and so on) an initialise method that you call after you create them, you pass this method a reference to your manager component that they store. Also they can call the manager when they are intialised and pass “this” so the manager could add them to a list of monsters.
Then if they die or whatever they inform the manager, and they can also check the manager (to see how many other enemies there are for instance)

The reason I like this kind of architecture is that everything already has the references they need and you never have to use any of unities search fucntions.