I want to make a function and effect that only when the monster is summoned, it has a specially buff effect. Plus, when the monster is destroyed, it also has a special buff effect.
I know I can write easy codes in start and ondestroy ed methods in the monster class to achieve this. However, the special buff is not the nature method of the monster. My designed special buff can only be triggered when special external conditions are met. Therefore, I do not want to write associated codes in monster class, because the buff do not belong to the nature functions but they come from external conditions.
How to achieve that by writing codes in a separate logic control script rather than by writing codes in target monster class
Blockquote
?
Would be a situation where these buffs (and death triggers, I suppose) ought to be applied by whatever is instancing these monsters. Would be a situation where something along the lines of a factory pattern is useful: Factory Method in C# / Design Patterns
Though in this case, your abstracted factory system would probably also include a post-processing step at the end to modify the monster just after its creation. Then any contextual buffs, triggers, etc, can be applied to the monster at this point in time. This might be on a global basis or local to whatever is instancing the monster.
A builder pattern could be useful here, too, allowing you to load up a ‘monster builder’ with extra data to be applied when it gets created. This can be more useful in case some buffs are dependant on the presence of other buffs, etc, as this gives you an opportunity to inspect that before the monster goes live.