- Home /
Can you trigger a function with an event in a base class conditionally?
I've got a class, from which I create several derived classes. Almost all of these need to perform the same function based on an event, but a couple of them don't need to do anything. The base class initializes things at runtime like so:
button.Release += OnRelease;
OnRelease() is defined in the base class. I can make some of the derived classes do nothing upon release of the button, using the new or override keywords in front of
void OnRelease() {};
...or I can remove the event trigger in the derived classes like this:
button.Release -= OnRelease;
...but that's a bit messy for my taste. Is there a better way?
Your answer
Follow this Question
Related Questions
UnityEvent Editor breaking in nested struct 1 Answer
EventSystem: prefabs that aren't in the scene don't accept GameObject 0 Answers
How do I have an event be triggered on an audio clip finishing playing? 1 Answer
Issues when hooking GUI to code 0 Answers
How to add an Interactable script component to a GameObject programmatically 1 Answer