Provides functionality for audio manipulation and playback, including volume and pitch adjustments, spatial considerations, and muting capabilities.
Properties
Collection of AudioClip to select from when playing.
Pitch will make audio sound higher or lower. The default value is 1, representing no change to the pitch. Lower values result in lower sounds, while higher values produce higher sounds. Valid values are from .01 to 2.
-- Set the pitch of the audio
audioShaderInstance.pitch = 1.2
A range from which a random value will be selected and applied to the pitch when playing. A value between [-randomPitch, randomPitch] will be added to the pitch when playing. The default value is 0, meaning no change to the pitch. Valid values are between 0 and 1.
-- Set the random pitch range of the audio
audioShaderInstance.randomPitch = 0.2
A range of random values to apply to the volume when playing. Will add [-randomVolume, randomVolume] to the volume.
-- Set the random volume range of the audio
audioShaderInstance.randomVolume = 0.1
The volume that the audio source will play. This is a normalized value (valid range is from 0 to 1).
-- Set the volume of the audio
audioShaderInstance.volume = 0.5
Determines whether the audio is currently muted.
Maximum range at which the clip can be heard
-- Set the spatial range of the audio
audioShaderInstance.spatialRange = 10
Methods
Get a random clip from the array of AudioClip. If there is only one AudioClip assigned, that clip will always be returned.
-- Get a random AudioClip
local randomClip = audioShaderInstance:GetRandomClip()
Returns
The randomly selected AudioClip object.
Play a random AudioClip from the clips array. Use PlayWithVolume or PlayWithVolumeAndPitch to specify volume and pitch.
-- Play a random AudioClip
audioShaderInstance:Play()
Returns
Play a random AudioClip from the clips array with a volume.
Parameters
v
Returns
Play a random AudioClip from the clips array, optionally specifying a volume and pitch. If volume and pitch are not provided, a default value of 1 is used for each.
Parameters
volume
The volume the clip will play. Note that this value may be affected by the AudioMixer in use.
pitch
The pitch the clip will play.
Returns
Create a new default audio shader from a UnityEngine.AudioClip. AudioShaders are used to play sound effects or music. They can contain any number of AudioClip in the 'clips' array. If there is more than one AudioClip, a random entry is selected each time the AudioShader is played.
Parameters
clip
The AudioClip to associate with the new AudioShader instance.
Returns
A new instance of AudioShader configured with the provided AudioClip.
Updated 17 days ago