Book Image

Unity 3D Game Development

By : Anthony Davis, Travis Baptiste, Russell Craig, Ryan Stunkel
Book Image

Unity 3D Game Development

By: Anthony Davis, Travis Baptiste, Russell Craig, Ryan Stunkel

Overview of this book

This book, written by a team of experts at Unity Technologies, follows an informal, demystifying approach to the world of game development. Within Unity 3D Game Development, you will learn to: Design and build 3D characters and game environments Think about the users’ interactions with your game Develop an interface and apply visual effects to add an emotional connection to your world Gain a solid foundation of sound design, animations, and lighting Build, test, and add final touches The book contains expert insights that you’ll read before you look into the project on GitHub to understand all the underpinnings. This way, you get to see the end result, and you’re allowed to be creative and give your own thoughts to design, as well as work through the process with the new tools we introduce. Join the book community on Discord to read this book with Unity game developers, and the team of authors. Ask questions, build teams, chat with the authors, participate in events and much more. The link to join is included in the book.
Table of Contents (16 chapters)
14
Other Books You May Enjoy
15
Index

Triggering sound through player interaction

All the sounds we’ve created so far are sounds that will play as soon as you enter a scene. This happens because we have Play On Awake checked in the Audio Source component.

If we don’t have this checked, sounds will never play. But what’s cool is we get to trigger sounds in other ways!

Triggering sound through Unity events

Let’s get a sound for our first stairs puzzle. This one will be quite easy. The easiest way for us to add our sound will be to add an Audio Source component directly to the trigger region GameObject. Let’s find LeftStairsTrigger and scroll down in the Inspector until we find the Interactio Trigger script, as shown in Figure 10.20.

Graphical user interface, application  Description automatically generated

Figure 10.20: Interaction Trigger script on the LeftStairsTrigger GameObject

If you recall, we made a UnityEvent called OnInteract, which we can utilize with our Audio Source component! Go ahead and click Add Component at the bottom...