Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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 Game Development Essentials

You're reading from   Unity Game Development Essentials If you have ambitions to be a game developer this guide is a must. Covering all the fundamentals of the Unity game engine, it will help you understand the different elements of 3D game creation through practical projects.

Arrow left icon
Product type Paperback
Published in Oct 2009
Publisher Packt
ISBN-13 9781847198181
Length 316 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Will Goldstone Will Goldstone
Author Profile Icon Will Goldstone
Will Goldstone
Arrow right icon
View More author details
Toc

Battery collection with triggers


To trigger the differing states of our Battery GUI, we will use a function called OnTriggerEnter() to detect interaction with objects that have trigger mode colliders, that is, our collectable batteries.

Before we add this function to our PlayerCollisions script, we will add a public member variable at the top to hold an audio clip to be played when the player picks up a battery as a form of audio-based feedback to back up the GUI element.

Open the PlayerCollisions script by double-clicking on its icon in the Scripts folder of the Project panel. This will launch the script in the script editor, or simply switch back to it for you, if you already have the file opened. Add a public member variable for the audio clip to the top of the script by adding the line:

var batteryCollect : AudioClip;

Remember that this is not assigned in the script, but simply left with a data type (AudioClip) so that it may be assigned in the Inspector later.

Next, place your cursor...

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 $19.99/month. Cancel anytime
Banner background image