Game Audio Development with Unity 5.X
上QQ阅读APP看书,第一时间看更新

Scripting Audio

Unity is a powerful game engine that provides an excellent editor interface that allows you to develop games without any coding skills using various predeveloped assets. However, while it is possible to build games without code, it is less practical and will just restrict your creativity in the end. The scripting engine in Unity is powerful and relatively easy to use, especially if you have any experience or knowledge of using a C style language (JavaScript, C, C++, Java, and C#). Even if you are here as a sound designer looking for tips on how to work with audio in Unity, you will benefit greatly from learning some scripting. For those of you who are quite familiar with scripting in Unity, don't run off to the next chapter. While this chapter will cover scripting at a basic level, it still will focus primarily on working with audio components.

This chapter will only teach you some basic Unity scripts in C# focused on using audio components. We will not go into details of syntax or language structure and it is intended as a phrase book for reuse. If you are interested in learning more about C# scripting in Unity, there are plenty of free online resources available, just a search away.

For this chapter, we will start with a very quick introduction into Unity scripting and then quickly dive into writing scripts. While a good part of this chapter will start with scripting in Unity, our primary focus will be to continue working with the various audio components, understanding good sound design principals, weapons, and physics as well as other audio techniques. The following list summarizes what we will cover in this chapter:

  • Introduction to scripting in Unity
  • Building a musical keyboard
  • Weapons and sound
  • Randomizing audio
  • Background music

For those of you continuing from the last chapter, you should have everything you need already. If you have jumped ahead to this chapter from the earlier one in this book, be sure you have Unity downloaded, installed, and configured. You will also need to download the book's source code from the Packt website and the Unity Viking Village sample project from the Asset Store. Refer back to Chapter 1, Introducing Game Audio in Unity, if you are unsure on how to locate and download this asset from the Asset Store.

As always, unless you are a Unity master, it will most certainly benefit you to complete the exercises as you read through the material in this chapter. There really is no better way to learn than to do.