Real Time Audio Switcher - Unity/c# (Unity 5.3, June 2016)

The video below details what I did and how I did it. Carry on reading below that for inclusion of some of the code changes I made.

Please excuse the code formatting! currently has a strange bug with indent spacing that I can't seem to shake (12th July 2016).

Changes to "GameManager.cs" are shown below.

Changes to "TankMovement.cs" are shown below.

There are a few more small changes throughout the project to complete the custom audio work. For the most part, these are duplicate versions of the code already in place but using new AudioSource components with a 3D position in the world. One element worthy of note was the change I made to the Shell Explosion sound. In the Tanks demo from Unity, when the shell fires, the particles/audio for it exploding are de-parented from the Parent Shell object, to make sure they still show/play when the Shell is removed from the game. I created another child object with a new AudioSource on it for my custom explosion sound, meaning I had to also de-parent that object from the Parent. The code changes to do this are shown below.

And finally, it's worth noting that these scripts make use of some Utility functions I wrote for non-linear transforms and range transformations. I blogged about those recently (which you can read here), but I've reproduced the code below as well.

And my Range.cs class, to be used in conjunction with the above.