-- For example, we have a short chime that we want to play every time a new avatar joins the scene.hostObject = Space.Host.ExecutingObjectfunctionwelcomeSound ()hostObject.Audio.Play()endSpace.Scene.OnPlayerJoin(welcomeSound)
Stop
void Stop ()
Stops playing the audio clip.
Space.Host.ExecutingObject.Audio.Stop()
hostObject = Space.Host.ExecutingObject;functionaudioOnOff ()if hostObject.Audio.IsPlaying thenhostObject.Audio.Stop();elsehostObject.Audio.Play();endSpace.Log(hostObject.Audio.IsPlaying);endhostObject.SubscribeToEvents();hostObject.OnMouseDown(audioOnOff);-- Now, we can make the sound play or stop playing just by clicking the object.
Pause
void Pause ()
Pauses the audio clip.
Space.Host.ExecutingObject.Audio.Pause()
hostObject = Space.Host.ExecutingObject;functionpauseOnOff ()if hostObject.Audio.IsPlaying thenhostObject.Audio.Pause();elsehostObject.Audio.UnPause();endSpace.Log(hostObject.Audio.IsPlaying);endhostObject.SubscribeToEvents();hostObject.OnMouseDown(pauseOnOff);-- Now, every time an object is clicked, the sound clip is paused/unpaused
UnPause
void UnPause ()
Pauses the audio clip.
Space.Host.ExecutingObject.Audio.UnPause()
hostObject = Space.Host.ExecutingObject;functionpauseOnOff ()if hostObject.Audio.IsPlaying thenhostObject.Audio.Pause();elsehostObject.Audio.UnPause();endSpace.Log(hostObject.Audio.IsPlaying);endhostObject.SubscribeToEvents();hostObject.OnMouseDown(pauseOnOff);-- Now, every time an object is clicked, the sound clip is paused/unpaused
hostObject = Space.Host.ExecutingObject;functionplayOnce ()hostObject.Audio.PlayOneShot(Space.Resources[0],0.5);endhostObject.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.
hostObject = Space.Host.ExecutingObject;functionaudioOnOff ()hostObject.Audio.Enabled =not hostObject.Audio.Enabled;Space.Log(hostObject.Audio.Enabled);endhostObject.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.
Loop
bool Loopgetset
Is looping of the sound clip enabled?
Space.Host.ExecutingObject.Audio.Loop =true
--the below script will make the object toggle it's Loop option OnClick--[Add "audio" reference to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjectaudio = Space.Host.GetReference("audio").AudioOnClick=function()audio.Loop =not audio.LoopendthisGameObject.AddClickable()thisGameObject.Clickable.OnClick(OnClick)
DopplerLevel
float DopplerLevelgetset
The Doppler level of the Audio Source. (See: Doppler Effect)
--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.ExecutingObjectslider = Space.Host.GetReference("slider").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.DopplerLevel = slider.Value *5--0 to 5endslider.OnValueChanged(OVC)
Volume
float Volumegetset
The Volume level of the Audio Source.
Space.Host.ExecutingObject.Audio.Volume =0.5
hostObject = Space.Host.ExecutingObject;Space.Log(hostObject.Audio.Volume);-- 1 by defaultfunctionaudioVolumeDecr ()if hostObject.Audio.Volume >0thenhostObject.Audio.Volume = hostObject.Audio.Volume -0.2;endSpace.Log(hostObject.Audio.Volume);endhostObject.SubscribeToEvents();hostObject.OnMouseDown(audioVolumeDecr);-- Now, every time we click this object, the Volume level is decreased by 0.2, until it reaches 0.
Pitch
float Pitchgetset
The Pitch level for the Audio Source.
Space.Host.ExecutingObject.Audio.Pitch =0.5
hostObject = Space.Host.ExecutingObject;Space.Log(hostObject.Audio.Pitch);-- 1 by defaultfunctionaudioPitchChange ()if hostObject.Audio.Pitch <3thenhostObject.Audio.Pitch = hostObject.Audio.Pitch +0.5;endSpace.Log(hostObject.Audio.Pitch);endhostObject.SubscribeToEvents();hostObject.OnMouseDown(audioPitchChange);-- Now, every time we click this object, the Pitch level is increased by 0.5, until it reaches 3.
Time
float Timegetset
Playback position in seconds.
Space.Host.ExecutingObject.Audio.Time =10
--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").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.Time = slider.Value * audio.Length -- from 0 to Length of clipendslider.OnValueChanged(OVC)
TimeSamples
int TimeSamplesgetset
Playback position in PCM samples.
Space.Host.ExecutingObject.Audio.TimeSamples =5
--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").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.TimeSamples = slider.Value * audio.Samples -- from 0 to number of samplesendslider.OnValueChanged(OVC)
--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").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.Time = slider.Value * audio.Length -- from 0 to Length of clipendslider.OnValueChanged(OVC)
--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").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.TimeSamples = slider.Value * audio.Samples -- from 0 to number of samplesendslider.OnValueChanged(OVC)
--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.ExecutingObjectOnUpdate=function()if thisGameObject.Seat.InUse thenifnot thisGameObject.Audio.IsPlaying then thisGameObject.Audio.Play()endelseif thisGameObject.Audio.IsPlaying then thisGameObject.Audio.Stop()endendendthisGameObject.Audio.Loop =truethisGameObject.SubscribeToEvents()thisGameObject.OnUpdate(OnUpdate)
PanStereo
float PanStereogetset
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.
Space.Host.ExecutingObject.Audio.PanStereo =-1
--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").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.PanStereo = (slider.Value *2) -1--(from -1 left to +1 right)endslider.OnValueChanged(OVC)
SpatialBlend
float SpatialBlendgetset
The level of impact 3D effects make on the AudioSource. 0 - no impact (full 2D sound), 1 - maximum impact (full 3D sound).
Space.Host.ExecutingObject.Audio.SpatialBlend =1
hostObject = Space.Host.ExecutingObject;functionspBlendChange ()if hostObject.Audio.SpatialBlend <1thenhostObject.Audio.SpatialBlend = hostObject.Audio.SpatialBlend +0.2;elsehostObject.Audio.SpatialBlend =0;endSpace.Log(hostObject.Audio.SpatialBlend);endhostObject.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.
Spatialize
bool Spatializegetset
Is spatialization enabled?
Space.Host.ExecutingObject.Audio.Spatialize =true
--the below script will make the object toggle it's Spatialize feature OnClick--[Add "audio" reference to the Scripting Runtime component]thisGameObject = Space.Host.ExecutingObjectaudio = Space.Host.GetReference("audio").AudioOnClick=function()audio.Spatialize =not audio.SpatializeendthisGameObject.AddClickable()thisGameObject.Clickable.OnClick(OnClick)
SpatializePostEffects
bool SpatializePostEffectsgetset
Is spatialization enabled before or after other filters are in action?
--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.ExecutingObjectaudio = Space.Host.GetReference("audio").AudioOnClick=function()audio.SpatializePostEffects =not audio.SpatializePostEffectsendthisGameObject.AddClickable()thisGameObject.Clickable.OnClick(OnClick)
ReverbZoneMix
float ReverbZoneMixgetset
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).
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").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.ReverbZoneMix = (slider.Value *1.1) --(from 0.0 to 1.1)endslider.OnValueChanged(OVC)
BypassEffects
bool BypassEffectsgetset
When true, none of global sound effects (reverbs, filters, etc.) are applied to the audio from this Audio Source.
--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.ExecutingObjectaudio = Space.Host.GetReference("audio").AudioOnClick=function()audio.BypassReverbZones =not audio.BypassReverbZonesendthisGameObject.AddClickable()thisGameObject.Clickable.OnClick(OnClick)
Spread
float Spreadgetset
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".
Space.Host.ExecutingObject.Audio.Spread =10.0
hostObject = Space.Host.ExecutingObject;functionincreaseSpread ()if hostObject.Audio.Spread <360thenhostObject.Audio.Spread = hostObject.Audio.Spread +90;endSpace.Log(hostObject.Audio.Spread);endhostObject.SubscribeToEvents();hostObject.OnMouseDown(increaseSpread);-- Every time an object is clicked, the spread increases by 90 degrees - compare the sound at different angles of spread!
Priority
int Prioritygetset
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.
Space.Host.ExecutingObject.Audio.Priority =50
hostObject = Space.Host.ExecutingObject;functionchangePriority ()if hostObject.Audio.Priority ==0thenhostObject.Audio.Priority =255;elsehostObject.Audio.Priority =0;endSpace.Log(hostObject.Audio.Priority);endhostObject.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.
Mute
bool Mutegetset
Is the audio muted? If True, the Volume is set to 0. If False, the Volume is restored to the original level.
Space.Host.ExecutingObject.Audio.Mute =true
hostObject = Space.Host.ExecutingObject;functionmuteOnOff ()hostObject.Audio.Mute =not hostObject.Audio.Mute;Space.Log(hostObject.Audio.Mute);endhostObject.SubscribeToEvents();hostObject.OnMouseDown(muteOnOff);-- Now clicking the object works like the Mute button.
MinDistance
float MinDistancegetset
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.)
Space.Host.ExecutingObject.Audio.MinDistance =2.0
--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").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.MinDistance = (slider.Value *20) +10--(from 10 to 30)endslider.OnValueChanged(OVC)
MaxDistance
float MaxDistancegetset
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.)
--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").UISlideraudio = Space.Host.GetReference("audio").AudioOVC=function()audio.MaxDistance = (slider.Value *40) +60--(from 60 to 100)endslider.OnValueChanged(OVC)
-- In this example, there are 3 audio clips in Scripting Runtime ResourceshostObject = Space.Host.ExecutingObject;local nextTrack =0;functionchangeTrack ()hostObject.Audio.AudioClip = Space.Resources[nextTrack];hostObject.Audio.Play();Space.Log(Space.Resources[nextTrack].Name);if nextTrack ==2then-- replace 2 with n-1, where n is the amount of audio clips you have added to ResourcesnextTrack =0;elsenextTrack = nextTrack +1;endendhostObject.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)!