0
0
Unityframework~20 mins

3D spatial audio in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
3D Spatial Audio Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Unity 3D spatial audio code?

Consider this Unity C# script attached to a GameObject with an AudioSource component. What will be the audible effect when the player moves away from the source?

Unity
using UnityEngine;

public class SpatialAudioTest : MonoBehaviour {
    void Start() {
        AudioSource audio = GetComponent<AudioSource>();
        audio.spatialBlend = 1.0f; // fully 3D
        audio.minDistance = 1f;
        audio.maxDistance = 10f;
        audio.Play();
    }
}
AThe sound stops immediately when the player moves beyond 1 unit.
BThe sound volume remains constant regardless of player distance.
CThe sound volume increases as the player moves away from the source.
DThe sound volume decreases smoothly as the player moves from 1 to 10 units away, then becomes inaudible beyond 10 units.
Attempts:
2 left
💡 Hint

Think about what minDistance and maxDistance control in 3D audio.

🧠 Conceptual
intermediate
1:30remaining
Which Unity AudioSource property controls how sound fades with distance?

In Unity's 3D audio system, which property determines how quickly the sound volume decreases as the listener moves away from the source?

ArolloffMode
BdopplerLevel
CspatialBlend
DminDistance
Attempts:
2 left
💡 Hint

It controls the shape of the volume drop-off curve.

🔧 Debug
advanced
2:30remaining
Why does this spatial audio script produce no sound?

Examine the following Unity C# script. The AudioSource component is attached and has an audio clip. Why does no sound play?

Unity
using UnityEngine;

public class AudioDebug : MonoBehaviour {
    void Start() {
        AudioSource audio = GetComponent<AudioSource>();
        audio.spatialBlend = 1.0f;
        audio.minDistance = 5f;
        audio.maxDistance = 15f;
        audio.Play();
    }

    void Update() {
        transform.position = new Vector3(100, 0, 0);
    }
}
AThe spatialBlend value is invalid and prevents playback.
BThe AudioSource is too far from the listener, beyond maxDistance, so sound is inaudible.
CThe audio clip is not assigned, so no sound plays.
DThe AudioSource component is missing, causing a null reference error.
Attempts:
2 left
💡 Hint

Check the position of the audio source relative to the listener.

📝 Syntax
advanced
2:30remaining
Which option correctly sets 3D spatial audio with a custom rolloff curve?

Choose the correct Unity C# code snippet that sets an AudioSource to fully 3D and applies a custom rolloff curve.

A
audio.spatialBlend = 1.0f;
audio.rolloffMode = AudioRolloffMode.Custom;
audio.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0,1,1,0));
B
audio.spatialBlend = 1.0f;
audio.rolloffMode = AudioRolloffMode.Custom;
audio.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0,0,1,1));
C
audio.spatialBlend = 1.0f;
audio.rolloffMode = AudioRolloffMode.Logarithmic;
audio.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0,1,1,0));
D
audio.spatialBlend = 0.0f;
audio.rolloffMode = AudioRolloffMode.Custom;
audio.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0,1,1,0));
Attempts:
2 left
💡 Hint

Remember that spatialBlend must be 1 for full 3D and the curve must go from volume 1 to 0.

🚀 Application
expert
3:00remaining
How to implement Doppler effect with 3D spatial audio in Unity?

You want to simulate the Doppler effect on a moving audio source in Unity. Which code snippet correctly enables and configures this effect?

A
audio.dopplerLevel = 1.0f;
audio.spatialBlend = 0.0f;
// Move source with velocity set on Rigidbody component
B
audio.dopplerLevel = 0.0f;
audio.spatialBlend = 1.0f;
// Move source with velocity set on Rigidbody component
C
audio.dopplerLevel = 1.0f;
audio.spatialBlend = 1.0f;
// Move source with velocity set on Rigidbody component
D
audio.dopplerLevel = 1.0f;
audio.spatialBlend = 1.0f;
// No Rigidbody velocity needed, just move transform.position
Attempts:
2 left
💡 Hint

Doppler effect requires velocity information from Rigidbody for accurate simulation.