Scripted Materials?

Hi, currently I’m completely new to unity. As I am new to gamedevelopment at all (having 8y exp in “SOLID” OOP-Programming), I’m looking for methods to handle situations individually and have a better separation of concerns.

May be I got the concept slightly wrong, but I’m looking for a way to get independent materials and prefabs that respond (or not respond) to some messages send to them on hit.

Say I have a gun and shoot on a stone-wall. This should have another cause like shooting on grass. In the first case, some kind of white and yellow particles should appear, in the other case, some green particles should spray around. This applies to sound as well. Shooting gras should sound differently than shooting, say, water, stone or wood.

I don’t want to have a central controller to be updated for every material introduced while progressing. It would be nice to have non-visible materials or material-prefab-like things to ship their own behavior on different hit-types. The hit-types are kind of predefined: Two kinds of Footsteps, three kind of weapon-hit-types (bullet, rocket/grenade, knife/sword).

So my idea was to listen for certain message-types and do something independently. Gras will spray on bullet-hit, an enemy will receive damage, may be show some red particles on hit and disappear when health is gone. Enemies also would have a dedicated receiver to handle the hit-damage and have a material to handle material-hits (robots) or flesh-hits (say, zombies).

Is there any tutorial to show how go work with this kind of encapsulated behavior, or is this even far away from whats usual or even possible with unity? I hope I could describe what I meant.

This is a common pattern. I would recommend you create an enum that is all of your impact types (bullet, footstepA, footsetpB, etc). Then may an array of Dictionaries the same size as the number of elements in the enum. Each dictionary should be keyed on a PhysicsMaterial and have as a value to Particle system or Prefab or whatever that you want to spawn on impact. Put the enum and data structure in some sort of global/static class and have each system that can trigger an impact store a member var that’s of type impact enum. When you want to make an impact, use the objects enum value and the PhysicsMaterial of the thing you just impacted to look up the effect/object to create.