# SAudioSource

## Index

### Functions Index

| Function Name                                                                                    |
| ------------------------------------------------------------------------------------------------ |
| void [**Play** ](#play)()                                                                        |
| void [**Stop** ](#stop)()                                                                        |
| void [**Pause** ](#pause)()                                                                      |
| void [**UnPause** ](#unpause)()                                                                  |
| void [**PlayOneShot** ](#playoneshot)(SResource clip, float volume)                              |
| void [**PlayClipAtPoint** ](#playclipatpoint)(SResource clip, SVector position, float volume=1f) |

### Properties Index

| Property Name                                                        |
| -------------------------------------------------------------------- |
| bool [**Enabled** ](#enabled)`get` `set`                             |
| bool [**Loop** ](#loop)`get` `set`                                   |
| float [**DopplerLevel** ](#dopplerlevel)`get` `set`                  |
| float [**Volume** ](#volume)`get` `set`                              |
| float [**Pitch** ](#pitch)`get` `set`                                |
| float [**Time** ](#time)`get` `set`                                  |
| int [**TimeSamples** ](#timesamples)`get` `set`                      |
| float [**Length** ](#length)`get`                                    |
| int [**Samples** ](#samples)`get`                                    |
| bool [**IsPlaying** ](#isplaying)`get`                               |
| float [**PanStereo** ](#panstereo)`get` `set`                        |
| float [**SpatialBlend** ](#spatialblend)`get` `set`                  |
| bool [**Spatialize** ](#spatialize)`get` `set`                       |
| bool [**SpatializePostEffects** ](#spatializeposteffects)`get` `set` |
| float [**ReverbZoneMix** ](#reverbzonemix)`get` `set`                |
| bool [**BypassEffects** ](#bypasseffects)`get` `set`                 |
| bool [**BypassListenerEffects** ](#bypasslistenereffects)`get` `set` |
| bool [**BypassReverbZones** ](#bypassreverbzones)`get` `set`         |
| float [**Spread** ](#spread)`get` `set`                              |
| int [**Priority** ](#priority)`get` `set`                            |
| bool [**Mute** ](#mute)`get` `set`                                   |
| float [**MinDistance** ](#mindistance)`get` `set`                    |
| float [**MaxDistance** ](#maxdistance)`get` `set`                    |
| SResource [**AudioClip** ](#audioclip)`get` `set`                    |

## Functions

### Play

void **Play** ()

*Starts playing the audio clip.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Play()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
-- For example, we have a short chime that we want to play every time a new avatar joins the scene.
hostObject = Space.Host.ExecutingObject

function welcomeSound ()
hostObject.Audio.Play()
end

Space.Scene.OnPlayerJoin(welcomeSound)
```

{% endtab %}
{% endtabs %}

### Stop

void **Stop** ()

*Stops playing the audio clip.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Stop()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function audioOnOff ()
if hostObject.Audio.IsPlaying then
hostObject.Audio.Stop();
else
hostObject.Audio.Play();
end
Space.Log(hostObject.Audio.IsPlaying);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioOnOff);
-- Now, we can make the sound play or stop playing just by clicking the object.
```

{% endtab %}
{% endtabs %}

### Pause

void **Pause** ()

*Pauses the audio clip.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Pause()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function pauseOnOff ()
if hostObject.Audio.IsPlaying then
hostObject.Audio.Pause();
else
hostObject.Audio.UnPause();
end
Space.Log(hostObject.Audio.IsPlaying);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(pauseOnOff);
-- Now, every time an object is clicked, the sound clip is paused/unpaused
```

{% endtab %}
{% endtabs %}

### UnPause

void **UnPause** ()

*Pauses the audio clip.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.UnPause()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function pauseOnOff ()
if hostObject.Audio.IsPlaying then
hostObject.Audio.Pause();
else
hostObject.Audio.UnPause();
end
Space.Log(hostObject.Audio.IsPlaying);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(pauseOnOff);
-- Now, every time an object is clicked, the sound clip is paused/unpaused
```

{% endtab %}
{% endtabs %}

### PlayOneShot

void **PlayOneShot** ([SResource](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/sresource) clip, float volume)

*Plays the audio clip just ones at a desired volume.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.PlayOneShot(AResource, 1.0)
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function playOnce ()
hostObject.Audio.PlayOneShot(Space.Resources[0],0.5);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(playOnce);
-- Now, every time the object is clicked, a sound clip we have in Scripting Runtime Resources is played at half the volume.

-- This happens regardless if the audio clip in the AudioClip property is playing or not.
```

{% endtab %}
{% endtabs %}

### PlayClipAtPoint

void **PlayClipAtPoint** ([SResource](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/sresource) clip,[ SVector](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/svector) position, float volume=1f)

*Function Description*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.PlayClipAtPoint(AResource, AVector)
--or
Space.Host.ExecutingObject.Audio.PlayClipAtPoint(AResource, AVector, 0.5)
```

{% endtab %}
{% endtabs %}

## Properties

### Enabled

bool **Enabled** `get` `set`

*Is the Audio Source component enabled?*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Enabled = false
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function audioOnOff ()
hostObject.Audio.Enabled = not hostObject.Audio.Enabled;
Space.Log(hostObject.Audio.Enabled);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioOnOff);
-- When the host object is clicked, the Audio Source component gets enabled, if it was disabled,
-- or disabled, if it was enabled, and its new state is printed to the console.
```

{% endtab %}
{% endtabs %}

### Loop

bool **Loop** `get` `set`

*Is looping of the sound clip enabled?*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Loop = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make the object toggle it's Loop option OnClick
--[Add "audio" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
audio = Space.Host.GetReference("audio").Audio


OnClick = function()
audio.Loop =  not audio.Loop
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### DopplerLevel

float **DopplerLevel** `get` `set`

*The Doppler level of the Audio Source. (See: Doppler Effect)*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.DopplerLevel = 0.5
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider change the Audio Source's Doppler Level
--[Add "slider" and "audio" references to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject

slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.DopplerLevel = slider.Value * 5 --0 to 5
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### Volume

float **Volume** `get` `set`

*The Volume level of the Audio Source.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Volume = 0.5
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;
Space.Log(hostObject.Audio.Volume);
-- 1 by default

function audioVolumeDecr ()
if hostObject.Audio.Volume > 0 then
hostObject.Audio.Volume = hostObject.Audio.Volume - 0.2;
end
Space.Log(hostObject.Audio.Volume);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioVolumeDecr);
-- Now, every time we click this object, the Volume level is decreased by 0.2, until it reaches 0.
```

{% endtab %}
{% endtabs %}

### Pitch

float **Pitch** `get` `set`

*The Pitch level for the Audio Source.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Pitch = 0.5
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;
Space.Log(hostObject.Audio.Pitch);
-- 1 by default

function audioPitchChange ()
if hostObject.Audio.Pitch < 3 then
hostObject.Audio.Pitch = hostObject.Audio.Pitch + 0.5;
end
Space.Log(hostObject.Audio.Pitch);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioPitchChange);
-- Now, every time we click this object, the Pitch level is increased by 0.5, until it reaches 3.
```

{% endtab %}
{% endtabs %}

### Time

float **Time** `get` `set`

*Playback position in seconds.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Time = 10
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set Audio Source's playback position (using seconds)
--[Add "slider" and "audio" references to the Scripting Runtime component]


slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.Time = slider.Value * audio.Length -- from 0 to Length of clip
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### TimeSamples

int **TimeSamples** `get` `set`

*Playback position in PCM samples.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.TimeSamples = 5
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set Audio Source's playback position (using PCM Samples)
--[Add "slider" and "audio" references to the Scripting Runtime component]

slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.TimeSamples = slider.Value * audio.Samples -- from 0 to number of samples
end


slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### Length

float **Length** `get`

*Return Audio Length.*

{% tabs %}
{% tab title="Lua" %}

```lua
AudioLength = Space.Host.ExecutingObject.Audio.Length
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set Audio Source's playback position (using seconds)
--[Add "slider" and "audio" references to the Scripting Runtime component]


slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.Time = slider.Value * audio.Length -- from 0 to Length of clip
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### Samples

int **Samples** `get`

*Return Audio Samples.*

{% tabs %}
{% tab title="Lua" %}

```lua
numSamples = Space.Host.ExecutingObject.Audio.Samples
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set Audio Source's playback position (using PCM Samples)
--[Add "slider" and "audio" references to the Scripting Runtime component]

slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.TimeSamples = slider.Value * audio.Samples -- from 0 to number of samples
end


slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### IsPlaying

bool **IsPlaying** `get`

*Is the sound clip playing right now?*

{% tabs %}
{% tab title="Lua" %}

```lua
numSamples = Space.Host.ExecutingObject.Audio.IsPlaying
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
 --this script will play a looping sound only if someone is using the seat
 --and will stop the sound if someone is not
--(Example: carnival game )
--[Object must contain a Seat component and AudioSource component]

thisGameObject = Space.Host.ExecutingObject


OnUpdate = function()
  if thisGameObject.Seat.InUse then
        if not thisGameObject.Audio.IsPlaying then
        thisGameObject.Audio.Play()
        end
  else
       if thisGameObject.Audio.IsPlaying then
        thisGameObject.Audio.Stop()
        end
  end
end

thisGameObject.Audio.Loop = true
thisGameObject.SubscribeToEvents()
thisGameObject.OnUpdate(OnUpdate) 
```

{% endtab %}
{% endtabs %}

### PanStereo

float **PanStereo** `get` `set`

*Pans the sound to the left or right. Values range from -1 to 1: 0 is the middle, -1 is full left, 1 is full right.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.PanStereo = -1
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set the Stereo Pan 
--[Add "slider" and "audio" references to the Scripting Runtime component]


slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.PanStereo = (slider.Value * 2) - 1 --(from -1 left to +1 right)
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### SpatialBlend

float **SpatialBlend** `get` `set`

*The level of impact 3D effects make on the AudioSource. 0 - no impact (full 2D sound), 1 - maximum impact (full 3D sound).*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.SpatialBlend = 1
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function spBlendChange ()
if hostObject.Audio.SpatialBlend < 1 then
hostObject.Audio.SpatialBlend = hostObject.Audio.SpatialBlend + 0.2;
else
hostObject.Audio.SpatialBlend = 0;
end
Space.Log(hostObject.Audio.SpatialBlend);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(spBlendChange);
-- Spatial Blend is increased by 0.2 every time the object is clicked, until it reaches 1.

-- Then with the next click, it resets back to 0.
```

{% endtab %}
{% endtabs %}

### Spatialize

bool **Spatialize** `get` `set`

*Is spatialization enabled?*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Spatialize = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make the object toggle it's Spatialize feature OnClick
--[Add "audio" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
audio = Space.Host.GetReference("audio").Audio


OnClick = function()
audio.Spatialize =  not audio.Spatialize
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### SpatializePostEffects

bool **SpatializePostEffects** `get` `set`

*Is spatialization enabled before or after other filters are in action?*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.SpatializePostEffects = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make the object toggle it's Spatialize Post Effects feature OnClick
--[Add "audio" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
audio = Space.Host.GetReference("audio").Audio


OnClick = function()
audio.SpatializePostEffects =  not audio.SpatializePostEffects
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### ReverbZoneMix

float **ReverbZoneMix** `get` `set`

*The level at which the audio coming from this Audio Source will be mixed into the global reverb of the scene (accomplished with Reverb Zones).*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.ReverbZoneMix = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
exa--the below script will make a slider set the Reverb Zone Mix value
--[Add "slider" and "audio" references to the Scripting Runtime component]


slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.ReverbZoneMix  = (slider.Value * 1.1) --(from 0.0 to 1.1)
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### BypassEffects

bool **BypassEffects** `get` `set`

*When true, none of global sound effects (reverbs, filters, etc.) are applied to the audio from this Audio Source.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.BypassEffects = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make the object toggle it's Bypass Effects feature OnClick
--[Add "audio" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
audio = Space.Host.GetReference("audio").Audio


OnClick = function()
audio.BypassEffects =  not audio.BypassEffects
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### BypassListenerEffects

bool **BypassListenerEffects** `get` `set`

*When true, whichever global effects are set on the Audio Listener will not be applied to the audio from this Audio Source.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.BypassListenerEffects = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make the object toggle it's Bypass Listener Effects feature OnClick
--[Add "audio" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
audio = Space.Host.GetReference("audio").Audio


OnClick = function()
audio.BypassListenerEffects =  not audio.BypassListenerEffects
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### BypassReverbZones

bool **BypassReverbZones** `get` `set`

*When true, the audio from this Audio Source is not mixed into the global reverb generated through Reverb Zones.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.BypassReverbZones = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make the object toggle it's Bypass Reverb Zones feature OnClick
--[Add "audio" reference to the Scripting Runtime component]

thisGameObject = Space.Host.ExecutingObject
audio = Space.Host.GetReference("audio").Audio


OnClick = function()
audio.BypassReverbZones =  not audio.BypassReverbZones
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)
```

{% endtab %}
{% endtabs %}

### Spread

float **Spread** `get` `set`

*The angle of spread of the audio channels in the 3D space (only works for stereo and multichannel audio). 0 by default - all channels are concentrated at the same speaker location, making it "mono".*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Spread = 10.0
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function increaseSpread ()
if hostObject.Audio.Spread < 360 then
hostObject.Audio.Spread = hostObject.Audio.Spread + 90;
end
Space.Log(hostObject.Audio.Spread);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(increaseSpread);
-- Every time an object is clicked, the spread increases by 90 degrees - compare the sound at different angles of spread!
```

{% endtab %}
{% endtabs %}

### Priority

int **Priority** `get` `set`

*The priority of this Audio Source: when there are more Audio Sources playing than channels available, Priority defines which channels will be discarded in favour of those with a higher priority. 0 is the highest priority, 255 - the lowest.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Priority = 50
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function changePriority ()
if hostObject.Audio.Priority == 0 then
hostObject.Audio.Priority = 255;
else
hostObject.Audio.Priority = 0;
end
Space.Log(hostObject.Audio.Priority);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(changePriority);
-- Now the Audio Source alternates between the highest and the lowest priorities.
-- This can be useful, for example, in a scene with an ambient sound set at Priority 128, where we have a speaker, which plays a certain looped audio nonstop.
-- When we want to hear the audio, we change it to the highest priority, so it blocks the ambient sound.
-- When we don't, we change it to the lowest, and the ambient sound dominates the scene again.
```

{% endtab %}
{% endtabs %}

### Mute

bool **Mute** `get` `set`

*Is the audio muted? If True, the Volume is set to 0. If False, the Volume is restored to the original level.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.Mute = true
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
hostObject = Space.Host.ExecutingObject;

function muteOnOff ()
hostObject.Audio.Mute = not hostObject.Audio.Mute;
Space.Log(hostObject.Audio.Mute);
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(muteOnOff);
-- Now clicking the object works like the Mute button.
```

{% endtab %}
{% endtabs %}

### MinDistance

float **MinDistance** `get` `set`

*At which distance from the Audio Source the sound will begin ceasing? The sound will be heard at its maximum volume within this distance. (Spatial Blend should not be equal to 0 for this property to take effect.)*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.MinDistance = 2.0
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set the Minimum Distance
--[Add "slider" and "audio" references to the Scripting Runtime component]


slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.MinDistance  = (slider.Value * 20) + 10 --(from 10 to 30)
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### MaxDistance

float **MaxDistance** `get` `set`

*At which distance from the Audio Source the sound will no longer be heard? (Spatial Blend should not be equal to 0 for this property to take effect.)*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.MaxDistance = 10.0
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
--the below script will make a slider set the Maximum Distance
--[Add "slider" and "audio" references to the Scripting Runtime component]


slider = Space.Host.GetReference("slider").UISlider
audio = Space.Host.GetReference("audio").Audio


OVC = function()
audio.MaxDistance  = (slider.Value * 40) + 60 --(from 60 to 100)
end

slider.OnValueChanged(OVC) 
```

{% endtab %}
{% endtabs %}

### AudioClip

[SResource](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/sresource) **AudioClip** `get` `set`

*The audio clip that is or will be played by this Audio Source.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.Audio.AudioClip = AResource
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```lua
-- In this example, there are 3 audio clips in Scripting Runtime Resources
hostObject = Space.Host.ExecutingObject;
local nextTrack = 0;

function changeTrack ()
hostObject.Audio.AudioClip = Space.Resources[nextTrack];
hostObject.Audio.Play();
Space.Log(Space.Resources[nextTrack].Name);
if nextTrack == 2 then -- replace 2 with n-1, where n is the amount of audio clips you have added to Resources
nextTrack = 0;
else
nextTrack = nextTrack + 1;
end
end

hostObject.SubscribeToEvents();
hostObject.OnMouseDown(changeTrack);
-- Now, every time the object is clicked, the next audio clip is played.
-- What's more, the list is looped (the index resets back to 0 when it gets to the end of the list)!
```

{% endtab %}
{% endtabs %}

### GameObject

[SGameObject](https://docs.breakroom.tech/scripting/client-scripting-api-reference/types/sgameobject) **GameObject** `get`

*Returns a reference to the GameObject of this component.*

{% tabs %}
{% tab title="Lua" %}

```lua
theGameObject = Space.Host.ExecutingObject.Audio.GameObject
```

{% endtab %}
{% endtabs %}
