Adding customized behaviors
While the Decorator pattern code we’ve been working with is almost exclusively focused on delegation, this design pattern also gives us the option of adding behaviors inside any concrete Decorators – and more importantly, firing off those behaviors whenever we choose!
Looking at this feature from the outside, the possibilities for customized behaviors in game scenarios are almost limitless, so we’ll stick to something extremely simple to avoid confusing game mechanics and Unity best practices with the underlying decorator code – we’re going to change the player’s color (I know, gasp!) when a specific concrete Decorator is applied.
In the Scripts folder, create a new C# script named HolyMail
and update its code to match the following code block. Our new concrete Decorator is going to take in a GameObject
target reference, so we know what object to apply the color change to, and decorate the Strength
stat...