lundi 24 octobre 2016

Unity c# multiple functions share the same behavior?

In my game, there are tons of places where I need to play audios after functions complete, for example

Class Player{
    public clip;
    void WalkToDestination()
    {
         //walk code here

         AudioManager.Play(clip);
    }
  }

Class GameManger{  
     public 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 clipinto the class, and AudioManager.Play(clip); into the body, there are too much repetitive work. is there any good design pattern for this?

Aucun commentaire:

Enregistrer un commentaire