(Added Play, Stop, Pause, UnPause, PlayOneShot) |
m (Added the Navbox) |
||
Line 258: | Line 258: | ||
''-- Now, every time the object is clicked, the next audio clip is played.'' <br> | ''-- Now, every time the object is clicked, the next audio clip is played.'' <br> | ||
''-- What's more, the list is looped (the index resets back to 0 when it gets to the end of the list)!''}} | ''-- What's more, the list is looped (the index resets back to 0 when it gets to the end of the list)!''}} | ||
+ | |||
+ | {{Scripting Navbox}} |
The SAudioSource class deals with the Audio Source component, which allows the object to play sounds in the scene.
Starts playing the audio clip.
hostObject = Space.Host.ExecutingObject;
function welcomeSound ()
end
Stops playing the audio clip.
function audioOnOff ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioOnOff);
Pauses the audio clip.
function pauseOnOff ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(pauseOnOff);
Unpauses the audio clip.
Plays the audio clip just ones at a desired volume.
function playOnce ()
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.
Is the Audio Source component enabled?
function audioOnOff ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioOnOff);
-- When the host object is clicked, the Audio Source component gets enabled, if it was disabled,
Is looping of the sound clip enabled?
Space.Log(hostObject.Audio.Loop);
-- False by default.
if not hostObject.Audio.Loop then
end
The Doppler level of the Audio Source. (See: Doppler Effect)
Space.Log(hostObject.Audio.DopplerLevel);
-- 1 by default
hostObject.Audio.DopplerLevel = 5;
The Volume level of the Audio Source.
Space.Log(hostObject.Audio.Volume);
-- 1 by default
function audioVolumeDecr ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioVolumeDecr);
The Pitch level for the Audio Source.
Space.Log(hostObject.Audio.Pitch);
-- 1 by default
function audioPitchChange ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(audioPitchChange);
Playback position in seconds.
Space.Log(hostObject.Audio.Time);
-- 0 by default (the beginning of the sound clip)
hostObject.Audio.Time = 15;
-- jumps to the 0:15 position of the sound clip
hostObject.Audio.Time = 75;
Is the sound clip playing right now?
Space.Log(hostObject.Audio.IsPlaying);
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.Log(hostObject.Audio.PanStereo);
-- Prints the current Pan Stereo level (0 by default)
hostObject.Audio.PanStereo = 0.5;
The level of impact 3D effects make on the AudioSource. 0 - no impact (full 2D sound), 1 - maximum impact (full 3D sound).
function spBlendChange ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(spBlendChange);
-- Spatial Blend is increased by 0.2 every time the object is clicked, until it reaches 1.
Is spatialization enabled?
Space.Log(hostObject.Audio.Spatialize);
-- Prints the current state of spatialization (False by default) to the console
hostObject.Audio.Spatialize = true;
Is spatialization enabled before or after other filters are in action?
-- Because enabling this property makes sense only if spatialization itself is enabled, let's enable it first.
hostObject.Audio.Spatialize = true;
if hostObject.Audio.Spatialize then
end
Space.Log(hostObject.Audio.SpatializePostEffects);
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).
Space.Log(hostObject.Audio.ReverbZoneMix);
-- prints "1" to the console (by default) - normal level of mixing in
hostObject.Audio.ReverbZoneMix = 0.5;
When true, none of global sound effects (reverbs, filters, etc.) are applied to the audio from this Audio Source.
Space.Log(hostObject.Audio.BypassEffects);
-- prints "False" to the console (by default);
hostObject.Audio.BypassEffects = true;
When true, whichever global effects are set on the Audio Listener will not be applied to the audio from this Audio Source.
Space.Log(hostObject.Audio.BypassListenerEffects);
-- prints "False" to the console (by default);
hostObject.Audio.BypassListenerEffects = true;
When true, the audio from this Audio Source is not mixed into the global reverb generated through Reverb Zones.
Space.Log(hostObject.Audio.BypassReverbZones);
-- prints "False" to the console (by default);
hostObject.Audio.BypassReverbZones = true;
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".
function increaseSpread ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(increaseSpread);
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.
function changePriority ()
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.
Is the audio muted? If True, the Volume is set to 0. If False, the Volume is restored to the original level.
function muteOnOff ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(muteOnOff);
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.)
hostObject.Audio.MinDistance = 10;
-- Now the sound will be heard at its maximum volume within 10 metres from the Audio Source.
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.)
hostObject.Audio.MaxDistance = 100;
The audio clip that is or will be played by this Audio Source.
hostObject = Space.Host.ExecutingObject;
local nextTrack = 0;
function changeTrack ()
end
hostObject.SubscribeToEvents();
hostObject.OnMouseDown(changeTrack);
-- Now, every time the object is clicked, the next audio clip is played.
|