|
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 is populated in Awake(), here: audioListener is defined as: What do I need to do differently?
(comments are locked)
|
|
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. tl;dr becomes
May 10 '12 at 09:58 AM
syclamoth
Converted way too much today. I see the issue, didn't realize that I was just being dumb. If I were not tired, this would have helped... (from the API docs) - for anyone else who may find this useful. This class implements a microphone-like device. It records the sounds around it and plays that through the player's speakers. You can only have one listener in a scene.
May 10 '12 at 10:03 AM
JSorrentino
The docs are actually a bit misleading in this way- there is actually nothing stopping there from being more than one audioListener- all that happens is that you get a huge slew of error messages at runtime. Basically, that's got nothing to do with the fact that it uses static variables for some of it's functionality- you still need an instance reference (which you are extracting properly, no problems there) in order to change 'velocityUpdateMode'.
May 10 '12 at 10:08 AM
syclamoth
(comments are locked)
|
