Hi there, got a question that’s sort of complicated (I think).
I have about 500
scriptable objects, each one with a different sound. I want them to be played when a specific condition (or multiple conditions) happen in my game.
How should I go about doing this?
Should I have events or conditions in the
scriptable object itself?
Should I have a reference to my
GameManager manager in each of the
scriptable objects and check every frame if that specific condition is met? Or the other way around, and have a reference to every
scriptable object in my
GameManager and check for every condition?
Should I have events instead? If so, how should I go about it?
I appreciate any help on how to solve this issue, thanks!
From your description, you may want to check out Events and Delegates.
Essentially this allows all the checking to done in the background and not by your scripts running endless checks in update or similiar high-resource requiring behaviour.
Essentially, it’s like putting a sensor on your umbrella in your closet. Every time the sensor detects rain, it beeps, so you hear it when leaving the house and take it with you. Events and Delegates will allow you to put on the sensor and leave the sensor to detect the condition you want it to act upon once detected.
These 3 resources have helped me understand and use events and delegates:
Unity Dojo - Videogame Development, Tips and Design Patterns: How to use Delegates in Unity. Like a BOSS.
Keep on Creating!
Justin of JustinTime Studio