Book Image

Unity 2D Game Development Cookbook

By : Claudio Scolastici
Book Image

Unity 2D Game Development Cookbook

By: Claudio Scolastici

Overview of this book

<p>Unity is a powerful game development engine that provides rich functionalities to create 2D and 3D games.</p> <p>Unity 2D Game Development Cookbook is a practical guide to creating games with Unity. The book aims to serve the purpose of exploring problematic concepts in Unity for 2D game development, offering over 50 recipes that are easy to understand and to implement, thanks to the step-by-step explanations and the custom assets provided. The practical recipes provided in the book show clearly and concisely how to do things right in Unity. By the end of this book, you'll be near "experts" when dealing with Unity. You will also understand how to resolve issues and be able to comfortably offer solutions for 2D game development.</p>
Table of Contents (15 chapters)
Unity 2D Game Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Game options – volume level


Among the extra features we are adding to the prototype, we'd like to provide an example of options screen functionality by showing you how to set up a horizontal slider to control the volume of the background music carpet.

Getting ready

For this recipe, we will use the bkgd_01 audio clip we imported at the beginning of this chapter. Open your project in Unity and ensure that bkgd_01 is configured in the Inspector window, as we did in the first recipe of this chapter.

How to do it...

  1. To make Option Screen for the prototype, we begin by creating a new scene and naming it Option Screen.

  2. Next, add an empty game object to the scene and name it GUI.

  3. Add an Audio Source component to the GUI game object in the scene. Remember that whenever you want a game object to play a sound, an Audio Source component must be attached to it.

  4. Now we add a script to the game object, with the instructions to draw the interface and control its functionality. Create a new C# script and name...