SoundEvent Functions

Reference of all the SoundEvent functions

The SoundEvent can be played directly from itself instead of playing via the SoundManager. A SoundManager instance in the scene is required to play SoundEvents.

Example code:

using UnityEngine;
using Sonity;

public class PlayStopExample : MonoBehaviour {

    public SoundEvent soundEvent;

    void PlayExample() {
        // Plays the SoundEvent at the position of the transform
        soundEvent.Play(transform);
    }

    void StopExample() {
        // Stops the SoundEvent playing at the transform
        soundEvent.Stop(transform);
    }
}

Play

Parameters

owner

The owner Transform

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

PlayAtPosition

Parameters

owner

The owner Transform

position

The Transform or Vector3 where is should play at (Transform can follow position)

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

Stop

circle-info

💡 TIP - Stopping Loops You really only need to use stop for looping or longer oneshot sounds (or the SoundContainer “Stop if Transform is Null” setting). Use the polyphony setting in the SoundEvent to manage the number of instances playing.

Parameters

owner

The owner Transform

position

The position Transform

allowFadeOut

If the SoundEvent should be allowed to fade out. Otherwise it is going to be stopped immediately

Pause and Unpause

Parameters

owner

The owner Transform

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

Get State, Length, Time and Contains Loop

Parameters

owner

The owner Transform

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

Get Spectrum Data

Parameters

owner

The owner Transform

samples

The array to populate with audio samples. Its length must be a power of 2

channel

The channel to sample from

window

The FFTWindow type to use when sampling

spectrumDataFrom

Where to get the spectrum data from

Get Last Played AudioSource

Parameters

owner

The owner Transform

Load or Unload Audio Data

UI Functions

Useful if you want to play SoundEvents without passing an owner.

UI Play

Parameters

localSoundTag

The SoundTag which will determine the Local SoundTag of the SoundEvent

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

position

The Transform or Vector3 where is should play at (Transform can follow position)

UI Stop

Parameters

allowFadeOut

If the SoundEvent should be allowed to fade out. Otherwise it is going to be stopped immediately

UI Pause and Unpause

Parameters

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

UI Get State, Length and Time

Parameters

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

Music Functions

Music Play

Useful if you want to play music with automatic stopping of the old music when playing a new song.

Parameters

stopAllOtherMusic

If all other SoundEvents played at the SoundManager music Transform should be stopped

allowFadeOut

If the other stopped SoundEvent should be allowed to fade out. Otherwise they are going to be stopped immediately

soundParameterInternals

For example SoundParameterVolumeDecibel is used to modify how the SoundEvent is played

Music Stop

Parameters

allowFadeOut

If the other stopped SoundEvent should be allowed to fade out. Otherwise they are going to be stopped immediately

Music Pause and Unpause

Parameters

forcePause

If the SoundEvent should be paused even if it is set to "Ignore Local Pause"

Music Get State, Length and Time

Parameters

pitchSpeed

Determines if it should be scaled by pitch. E.g. -12 semitones will be twice as long

Last updated