Using an Event?

Would using an event when the enemy dies, and also when the enemy reaches the end of the path be a viable option?
Would the bank have to Subscribe to every enemies Events constantly? or would the initial Subscription be enough?
I am interested in this approach but only know enough about events to get me into trouble, lol.

Edit: Since we’re using a pool, Could you use an Event[], to subscribe to all the separate enemies events?

Yes, while it’s not the only way to do it, it’s a good way to do it.

What’s a bank in this context?

I don’t get what you’re asking. How would you be using an array of events?

It’s more advanced programming than simple events, but consider using a ScriptableEvent / ScriptableEvent Listener. You can learn more about them here: Overthrowing the MonoBehaviour Tyranny in a Glorious Scriptable Object Revolution

Thanks for the reply, this question was specifically in regards to the Real Rush tutorial… The bank is the script that is adding and subtracting gold form the current currency.
The Pool, is the Object pool that holds our Enemies…
When subscribing to the Enemy’s events, would the bank have to subscribe to All of the enemy’s in the pool, or just one of them? I assume it would need to subscribe to all of them… so I am not sure how to implement that.

I don’t remember an object pool with the enemies or events in Realm Rush.

It depends on how you’re setting it all up. Typically all of them, but it sounds like you’re trying to set it up in a slightly odd way. I wouldn’t expect it to be the banks responsibility to chase down the enemies as it potentially sets yourself up for a cyclical dependency issue.

How I would set it up would be some sort of event that gets triggered whenever an enemy reaches their goal, say on an object with a script called ExitHandler.cs or something like that and have a public event called something like onEnemyEscape where the bank, life, mana count, score subscribes to it to let them know there’s an escape. Any time an enemy escapes, it calls something like FindObjectOfType<ExitHandler>.onEnemyEscape?.Invoke(enemyDetails); depending on how you need to set it up. This way, you can add on extra handlers who care about enemies escaping.

If you’re not going to have more handlers, a simpler way is really to have the enemies report an escape/reached goal when they reach the end goal with a ‘FindObjectOfType().OnEnemyEscape(enemyDetails);’

Setting up an Event Handler Script is a great idea! At least so far, Realm Rush hasn’t used events, but did set up an Object pool, so I was curious how events could be handled. Thank you

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms