Unity: Adding sound effects to the power ups

Objective: We need to make it so that our power up sound effect plays when each of the power ups are picked up.

To start we need to go into our power up script and add a variable that’ll hold the power up sound effect.

Next we need to use a new function called play clip at point since if we were to do it by playing the clip through the audio source like we’ve been doing with the other sound effects the clip won’t play because the object is being destroyed before it even has time to play. Play clip at point allows us to play the clip until it is finished playing and then destroys it after it’s done playing.

To use play clip at point we need to add an audio source in the script then play clip at point with the audio clip for the power up we made and a position to play it at and since we just want it played at the position it was picked up we can just say transform.position.

--

--

--

I am hard working Game development student learning as much about game development and unity as possible.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Automate deploying a Dockerized PHP application with Gitlab CI

Android NDK: Using C/C++ Native Libraries to Write Android Apps

Migrating Mongo DB to Azure Cosmos DB using Migration Tool

Hacking microservices performance using AWS SQS

Practical Introduction to Strategy Design Pattern Using Java

How WhatsApp Bot is helping us improve customer support experience

CS371p Spring 2021: Week 3

Kubernetes how to access Dashboard

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jake Boere

Jake Boere

I am hard working Game development student learning as much about game development and unity as possible.

More from Medium

Indy Pro ’22: Talent Training

How to Switch Between Cameras with Cinemachine and Timeline

MVC Pattern in Unity — Less Code Dependency and Better Code Architecture

Cleaning up the Homing Missile code