- Home /
Making sound names error resistant in an AudioManager
If I create an array of the following class in a MonoBehaviour class, I can fill soundID (name) and corresponding AudioClip and I can easily refer to specific AudioClip with it's soundID wherever I want to play relevant audio.
[Serializable]
public class CSound
{
public string soundID;
public AudioClip clip;
}
The problem is, if by mistake, I change the soundID in the editor or in wherever I make a call to my AudioManager to play a specific file, the whole thing will be broken.
In c++ I could set all those soundIDs (strings) to a constant and by using that constant I could make the same call to AudioManager with a predefined value, where if I mistype the constant's name, it wouldn't compile at all hence giving me strong protection against human errors.
Is there anyway to do something similar here while not losing the comfort of dragging & dropping AudioClip assets to the appropriate values in the editor and while keeping this manager dynamic and while not creating custom scripts per sound groups (script per scene)?
one way would be using enum values. since you were writing one constant in C++ for each clip you can do the same for the enum. just make sure you never remove entries from it because it will change all following enums wherever used. rename them only.
Your answer
Follow this Question
Related Questions
Change Unity 3d Audio Spatializer Plugin 0 Answers
Is there any way of detecting what type of audio is recorded using microphone? 1 Answer
Unity not playing audio 0 Answers
Any way to disable log message "There are no audio listeners..."? 6 Answers
Audio Clip doesn't work in editor preview or on an object with a source. 0 Answers