0
0
Unityframework~10 mins

3D spatial audio in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add an AudioSource component to the GameObject.

Unity
AudioSource audioSource = gameObject.AddComponent<[1]>();
Drag options to blanks, or click blank then click option'
AAudioSource
BAudioClip
CAudioListener
DAudioMixer
Attempts:
3 left
💡 Hint
Common Mistakes
Using AudioListener instead of AudioSource.
Trying to add AudioClip as a component.
Confusing AudioMixer with AudioSource.
2fill in blank
medium

Complete the code to set the AudioSource to play a 3D sound.

Unity
audioSource.spatialBlend = [1]f;
Drag options to blanks, or click blank then click option'
A0.0
B0.5
C1.0
D2.0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.0f which makes the sound 2D.
Using values greater than 1.0f which are invalid.
Using 0.5f which is a mix but not fully 3D.
3fill in blank
hard

Fix the error in setting the AudioSource's rolloff mode to logarithmic.

Unity
audioSource.rolloffMode = AudioRolloffMode.[1];
Drag options to blanks, or click blank then click option'
ALinear
BLogarithmic
CConstant
DExponential
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'logarithmic' with wrong casing.
Using 'Exponential' which is not a valid option.
Using 'Constant' which does not change volume with distance.
4fill in blank
hard

Fill both blanks to create a dictionary mapping audio clip names to AudioClip objects and filter clips longer than 3 seconds.

Unity
var longClips = clips.Where(clip => clip.length [2] 3).ToDictionary(clip => [1], clip => clip);
Drag options to blanks, or click blank then click option'
Aclip.name
B>
C<
Dclip.length
Attempts:
3 left
💡 Hint
Common Mistakes
Using clip.length as key instead of clip.name.
Using '<' instead of '>' for filtering.
Using clip.name as value instead of key.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase clip names to their lengths for clips shorter than 5 seconds.

Unity
var shortClipLengths = clips.Where([3] => [3].length < 5).ToDictionary([3] => [1], [3] => [2]);
Drag options to blanks, or click blank then click option'
Aclip.name.ToUpper()
Bclip.length
Cclip
Dclip.name
Attempts:
3 left
💡 Hint
Common Mistakes
Using clip.name instead of clip.name.ToUpper() for keys.
Using wrong loop variable name.
Mixing up keys and values.