When should i be using events
Hello, so i recently started using events and idk if what i am doing is good performance wise.
I have these units with a OnFire event and on these units there is a TakeDamage method that we subscribe to the OnFire event. And we then pass in a gameobject parameter so we know if it's the target we are supposed to be hitting.
Is this better then just flat out calling the TakeDamage method on the enemy? Or is this just using too much CPU?
Thanks in advance!
Answer by itchyOwl · Feb 05, 2018 at 01:16 PM
It's not about performance. It's about design. Events are quite performant even when when used frequently, but the main reason to use them is to encapsulate your code so that there are a clear responsibilities (or even a single responsibility) for each class.
Your answer
Follow this Question
Related Questions
How do I optimize my code?,How do I optimize my script? 1 Answer
Mobile Optimization question 1 Answer
How Can I Run C# Script Through Unity Event 2 Answers
if collider != trigger //do stuff 1 Answer