Set 3D Audio Options
What it does: Enables and sets the possible 3D audio options needed and returns an AudioError (see Possible Errors), showing wheter and how setting the 3D audio options failed.
- DOES_NOT_EXIST
- MISSING_WRAPPER
- MISSING_SOURCE
- MISSING_CLIP
- CAN_NOT_BE_3D
How to call it:
SoundNameis thenamewe have given the sound we want to playMinDistanceis the distance the sound will not get louder atMaxDistanceis the distance the sound will still be hearable atChildis theChildTypethat we want to call this method onSpatialBlenddefines how much the sound is affected by 3D (0f = 2D, 1f = 3D)Spreadis the angle the sound will be emitted at in degrees (0f - 360f)DopplerLeveldefines the doppler scale for our sound (0f - 5f)RolloffModedefines how the sound should decline involumebetween the min and max distance
string soundName = "SoundName";
float minDistance = 1f;
float maxDistance = 500f;
ChildType child = ChildType.PARENT;
float spatialBlend = 1f;
float spreadAngle = 0f;
float dopplerLevel = 1f;
AudioRolloffMode rolloffMode = AudioRolloffMode.Logarithmic;
AudioError err = am.Set3DAudioOptions(soundName, minDistance, maxDistance, child, spatialBlend, spreadAngle, dopplerLevel, rolloffMode);
if (err != AudioError.OK) {
Debug.Log("Setting 3D audio options for the sound called: " + soundName + " failed with error id: " + err);
}
else {
Debug.Log("Setting 3D audio options for the sound called: " + soundName + " succesfull");
}
Alternatively you can call the methods with less paramters as some of them have default arguments.
string soundName = "SoundName";
AudioError err = am.PlayAt3DPosition(soundName);
if (err != AudioError.OK) {
Debug.Log("Setting 3D audio options for the sound called: " + soundName + " failed with error id: " + err);
}
else {
Debug.Log("Setting 3D audio options for the sound called: " + soundName + " succesfull");
}
When to use it: When you want to make a 2D sound gain 3D capabilities via. code instead of the ScriptableObject.