Audio Source Component

From Pummel Party Mod Documentation
Jump to navigation Jump to search

The audio source component is an Audio Component that can play sound from a point in the scene. It can also play sounds with no in-world position, such as background music.

The component includes a button in the inspector to preview the sound relative to the camera's position. This can be used to hear how the component's settings will affect the sound without needing to enter play mode.

Component Settings

The Audio Source component in the Inspector Window.
Property Description
General
Audio Source Type The type of the audio source. Choose SFX for any sound that plays in the scene and Music for any music tracks. This affects which volume settings will apply to this audio source.
Audio Clip The audio clip or sound file to play.
Playing
Play On Awake The audio source will start playback as soon as the game starts.
Loop Should the audio source play the audio clip on repeat once it has started.
Pitch Adjust the pitch of the audio clip playback. This will also change the speed of playback, with higher pitches playing the sound faster and lower pitches taking longer to play.
Sound
Volume The loudness of the sound.
2D/3D Sound Blend The ratio of the sound being played in "2D" vs "3D".

2D sounds can be heard from anywhere and will be heard with no direction. I.e. the position of the audio source doesn't influence the sound.
3D sounds can only be heard from within the max distance range of the Audio Source and the sound will appear to come from the position of the audio source in 3D space.

Stereo panning (2D sound only) How the sound should be split between the left and right ear.
  • -1 is completely through the left ear.
  • 0 is balanced between the two ears.
  • 1 is completely through the right ear.
Rolloff Mode (3D sound only) How the volume of the sound should decrease over time. The volume will follow this type of curve from the Min Distance to the Max Distance.
Min Distance (3D sound only) The minimum distance before the volume begins to drop off. When closer than this distance the full volume is used. After this distance, the volume drops off according to the Rolloff Mode until the Max Distance.
Max Distance (3D sound only) The maximum distance before the audio source cannot be heard anymore. (Note: When using Logarithmic roll-off mode, the audio will still be audible beyond this point, but will be extremely quiet).
Use Doppler Effect (3D sound only) Should this audio source use the Doppler Effect.

Example Usage

Playing spatial music or ambience

You can use the audio source to play music or ambience in one part of the scene. You could play the sound of frogs croaking near a pond, or some music near a radio, but set the 3D sound Max Distance small so that it drops off when not nearby.

If you instead want general looping background music or ambience that can be heard from everywhere, you can set these using the Mod Settings.

Playing sound mid-game

You can make an audio source play while the game is running at a specific time by using a Play Sound Action. The play sound action will play a sound globally by default, but if you set the action's Target to Advanced and set an Audio Source as the advanced target, it will cause the audio source to play the sound, or cause the audio source to play its own sound if no clip is provided to the play sound action.