As a support unit, Soundmanager and loader play a very important role in the game. Since these two things are relatively simple, they will be explained in this article.
First say Soundmanager:
Soundmanager and Gamemanager, just need one at the same time, so also set as singleton mode. So in the awake method and Gamemanager basically the same.
It can be noted that in unity it is not entirely simple to select a sound clip and then play it, but to bind a sound to a "audiosource".
Audiosource can be understood as a "DJ", a DJ that can add effects to the sound and decide when to play a sound. At the same time for some 3d games, the relationship between the DJ's location and your location, as well as the placement of your scene will affect the sound you hear (of course, this effect is rarely used by our God-viewing game)
It is worth noting that the Randomizesfx method in this:
In addition to randomly choose a play from a few sound effects, but also add the pitch effect, in here is to add a little bit of sound pitch changes, so that the sound seems more random.
Again, say loader:
This class is very, very simple, and the only purpose now is to instantiate the Gamemanager. "Why does a similar soundmanager not have to be instantiated in code?" "Because there's already a soundmanager in the hierarchy view that we dragged in, kid! ”
In fact, there are other things that can be done in addition to instantiating Gamemanager, but in this case there is not much work to do, so this is the only thing to do here first.
In addition, if a script wants to run, the one thing necessary is to cling to a gameobject, and here we choose Maincamera as the object of this attachment. The main reason I personally think it may be because this object is not easily destroyed, and for the other objects we create basically no dependency, high independence, so it is appropriate to do this kind of guided work.
Well, the whole story is almost over, and the last one we'll talk about the UI, basically this thing even finished, and then if there is anything else that needs to be added will also open the article alone.
Unity5 Official tutorial Note (2D Rogue like) 06--soundmanager and Loader