Converting from js to c#...

I’m converting from js to c# and hit this error:

error CS0176: Static member `UnityEngine.AudioListener.volume’ cannot be accessed with an instance reference, qualify it with a type name instead

Here’s the code:

audioListener.volume = 0.0f; // This is the line returning the error above.

audioListener is populated in Awake(), here:

audioListener = GameObject.FindGameObjectWithTag("MainCamera").transform.GetComponent<AudioListener>();

audioListener is defined as:

public static AudioListener audioListener;

What do I need to do differently?

In this case, it’s because


is itself a static variable! As such, you can’t access it from an instance, because it should be accessed only as a member of the class itself. In this case, whenever you want to change the volume, all you have to do is use that one line instead of trying to find the current audioListener in the scene.