In my game, there are tons of places where I need to play audios after functions complete, for example:
class Player{
public AudioClip clip;
void WalkToDestination()
{
//walk code here
AudioManager.Play(clip);
}
}
class GameManger{
public AudioClip clip;
void AfterCompleteLevel()
{
//play level completion animation
AudioManager.Play(clip);
}
}
Since there are so many functions requiring playing sound, and every time I have to add
public AduioSource clip
into the class, and AudioManager.Play(clip);
into the body, there are too much repetitive work.
Is there any good design pattern for this?