Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AudioSource

Namespace: UnityEngine

/

Inherits from: Behaviour

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

A representation of audio sources in 3D.

An AudioSource is attached to a GameObject for playing back sounds in a 3D environment. In order to play 3D sounds you also need to have a AudioListener. The audio listener is normally attached to the camera you want to use. Whether sounds are played in 3D or 2D is determined by AudioImporter settings.

You can play a single audio clip using Play, Pause and Stop. You can also adjust its volume while playing using the volume property, or seek using time. Multiple sounds can be played on one AudioSource using PlayOneShot. You can play a clip at a static position in 3D space using PlayClipAtPoint.

See Also: AudioListener, AudioClip, AudioSource component.

Variables

bypassEffectsBypass effects (Applied from filter components or global listener filters).
bypassListenerEffectsWhen set global effects on the AudioListener will not be applied to the audio signal generated by the AudioSource. Does not apply if the AudioSource is playing into a mixer group.
bypassReverbZonesWhen set doesn't route the signal from an AudioSource into the global reverb associated with reverb zones.
clipThe default AudioClip to play.
dopplerLevelSets the Doppler scale for this AudioSource.
ignoreListenerPauseAllows AudioSource to play even though AudioListener.pause is set to true. This is useful for the menu element sounds or background music in pause menus.
ignoreListenerVolumeThis makes the audio source not take into account the volume of the audio listener.
isPlayingIs the clip playing right now (Read Only)?
loopIs the audio clip looping?
maxDistance(Logarithmic rolloff) MaxDistance is the distance a sound stops attenuating at.
minDistanceWithin the Min distance the AudioSource will cease to grow louder in volume.
muteUn- / Mutes the AudioSource. Mute sets the volume=0, Un-Mute restore the original volume.
outputAudioMixerGroupThe target group to which the AudioSource should route its signal.
panStereoPans a playing sound in a stereo way (left or right). This only applies to sounds that are Mono or Stereo.
pitchThe pitch of the audio source.
playOnAwakeIf set to true, the audio source will automatically start playing on awake.
prioritySets the priority of the AudioSource.
reverbZoneMixThe amount by which the signal from the AudioSource will be mixed into the global reverb associated with the Reverb Zones.
rolloffModeSets/Gets how the AudioSource attenuates over distance.
spatialBlendSets how much this AudioSource is affected by 3D spatialisation calculations (attenuation, doppler etc). 0.0 makes the sound full 2D, 1.0 makes it full 3D.
spreadSets the spread angle a 3d stereo or multichannel sound in speaker space.
timePlayback position in seconds.
timeSamplesPlayback position in PCM samples.
velocityUpdateModeWhether the Audio Source should be updated in the fixed or dynamic update.
volumeThe volume of the audio source (0.0 to 1.0).

Public Functions

PausePauses playing the clip.
PlayPlays the clip with an optional certain delay.
PlayDelayedPlays the clip with a delay specified in seconds. Users are advised to use this function instead of the old Play(delay) function that took a delay specified in samples relative to a reference rate of 44.1 kHz as an argument.
PlayOneShotPlays an AudioClip, and scales the AudioSource volume by volumeScale.
PlayScheduledPlays the clip at a specific time on the absolute time-line that AudioSettings.dspTime reads from.
SetScheduledEndTimeChanges the time at which a sound that has already been scheduled to play will end. Notice that depending on the timing not all rescheduling requests can be fulfilled.
SetScheduledStartTimeChanges the time at which a sound that has already been scheduled to play will start.
StopStops playing the clip.
UnPauseUnpause the paused playback of this AudioSource.

Static Functions

PlayClipAtPointPlays an AudioClip at a given position in world space.

Inherited members

Variables

enabledEnabled Behaviours are Updated, disabled Behaviours are not.
isActiveAndEnabledHas the Behaviour had enabled called.
gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject (null if there is none attached).
hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

Public Functions

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagIs this game object tagged with tag ?
GetComponentReturns the component of Type type if the game object has one attached, null if it doesn't.
GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the component of Type type in the GameObject or any of its parents.
GetComponentsReturns all components of Type type in the GameObject.
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.
GetComponentsInParentReturns all components of Type type in the GameObject or any of its parents.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the game object.

Static Functions

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares if two objects refer to the same.