Learn to code by making a 2D space shooter game.

Suleiman Abdullah
2 min readJan 23, 2022

Objective: Implement Powerup sound in another way.

The first step selects all powerups to add an audio source component.

The next step is to go through the powerup scripts, create an audio source variable and cache it to the start method.

The next step is to drag a powerup sound clip and drag it to both powerup prefabs in the project folder.

remember to disable player on wake option on radio source

If we call audio source. Play it won't work, because all code will be run in the same frame because destroy method will destroy powerup object we won't hear the audio.

To solve this issue let's create a sprite render variable and assign the component in the start method.

Let us disable the sprite render then Play the powerup sound to give the illusion that we collect it .

Last let us delay the destroy the game object for about 3 seconds to make sure the sound clip is played to the end.

This is another way to play sound simultaneous while giving the player the illusion that he successfully collect the powerup.

Twiiiiiiiiiiiiiiiiiiiii this is the sound when we collect any powerup

See you in the next article.

--

--

Suleiman Abdullah

Self taught Unity Developer, who is passion about making games ,and he loves Math For Game Development