I am struggling a bit to grasp the intent of the event system. Here is my case;
- I have a GUI, that display number of beasts in a scene via some icons
- I have mobs, that run around in a scene
- Mobs can be added by the player
- Mobs can die, if that happens a few functions need to be called, sound, internal administration, etc.
So, game runs, a mob dies, I have written a function that handles that and I want to be able to call that via an event. Call the event, and the GUI get’s updated, the number of mobs active becomes one lower, room for one mob is created etc. I have created the event “MobDies” via
public UnityEvent MobDies; in a seperate CS file “MobEvents.cs”. That script is then attached to an empty object in the scene. And in the inspector I dragged the functions that need to happen once the event triggers does into the event. When I now do
MobDies.Invoke(); in MobEvents.cs, it works perfectly.
But, how do I trigger that event outside of MobEvents.cs? Every mob for instance has a MobController.cs that contains a Die function, I would like to put something like Event.Trigger("MobDies"); or the like in there, so trigger a globale event, like a mouseclick. But how do I do that? Is that the right way to go about that? Or should I add a pointer to every Mob that I instantiate so it can invoke the events that way?
