I’m building a system where I want to have shields, then armor, then health. I want to call something like ApplyDamage( amount_of_damage ) and have it call shields first and let the shields reduce the amount of damage based on the shield type, power and health, and if anything remains then call the same on armor and again on health. It’s easy to do if I name them different things, but I wanted it to work so even if the player didn’t have a shield or armor, the code would work unchanged.
I tried Broadcast hoping it would stop when it hit the first one, but all 3 get called.
I looked to try SendMessage, but it only works on the current level, not sub/nested levels.
It’s easy enough to do if I call things directly but I was hoping there’s a cleaner way to do it. It seems Broadcast or SendMessage would be ideal, but if so I don’t see it?
Sounds like the chain of responsibility may be a good approach.
If the shields fail, it passes it to the armor, if that fails it passes it to the health. The design pattern would allow for more or less items to exist on each.
Thanks Karljj1 but not quite what I was asking. The programming is easy but Unity is a component based system not a classic OO system. Although you can use OO methodologies its not necessary or ideal for a component based system. Instead I’m looking to use the components in a nested fashion where A cals B calls C and so forth but if any are missing it just skips and goes to the next.
I’d like to see something like sendmessagedown which just calls the method on any 1st level sub object. Then I could nest the objects to get what I want in a component kind of way. I don’t see anything like that but wondering if I’m just missing it or if someone has created such a thing already. If its not available I’ll just do it myself, but this is a core concept for component systems so I have to believe its there and I’m just misusing/misunderstanding a concept somewhere in how unity is structured?