Consider this Unity C# script attached to a GameObject with an AudioListener component. What will be printed in the console?
using UnityEngine;
public class AudioListenerTest : MonoBehaviour
{
void Start()
{
AudioListener listener = GetComponent<AudioListener>();
Debug.Log(listener.enabled);
listener.enabled = false;
Debug.Log(listener.enabled);
}
}Think about the default state of the AudioListener component and what happens when you disable it.
The AudioListener component is enabled by default, so the first Debug.Log prints True. Then it is disabled, so the second Debug.Log prints False.
Choose the correct statement about the AudioListener component in Unity.
Think about how audio is heard in a 3D space in Unity.
AudioListener acts like ears in the scene and captures audio from all AudioSources based on its position. Having multiple active AudioListeners causes errors. It does not depend on the camera or screen resolution.
Examine the code below. Why does it cause an error?
using UnityEngine;
public class ListenerToggle : MonoBehaviour
{
void Update()
{
AudioListener.enabled = !AudioListener.enabled;
}
}Consider how you access component properties in Unity scripts.
enabled is an instance property of the AudioListener component. You must get a reference to the component instance before toggling enabled. Accessing it via the class name causes a compile-time error.
Choose the correct code snippet to disable the AudioListener component attached to the same GameObject.
Remember how to access components in Unity scripts.
GetComponent
You have two cameras in your scene, each with an AudioListener component. You want to enable the AudioListener on the active camera and disable it on the other. Which code snippet correctly does this?
Think about how to enable one AudioListener and disable the other using component access.
Option C correctly defines methods to enable and disable the AudioListener component on the given cameras. Option C is correct but incomplete as a snippet without context. Option C is invalid syntax. Option C tries to access AudioListener as a property which does not exist.