Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unity 3D Game Development

You're reading from   Unity 3D Game Development Designed for passionate game developers—Engineered to build professional games

Arrow left icon
Product type Paperback
Published in Aug 2022
Publisher Packt
ISBN-13 9781801076142
Length 370 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (4):
Arrow left icon
Anthony Davis Anthony Davis
Author Profile Icon Anthony Davis
Anthony Davis
Ryan Stunkel Ryan Stunkel
Author Profile Icon Ryan Stunkel
Ryan Stunkel
Russell Craig Russell Craig
Author Profile Icon Russell Craig
Russell Craig
Travis Baptiste Travis Baptiste
Author Profile Icon Travis Baptiste
Travis Baptiste
Arrow right icon
View More author details
Toc

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime