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.