So, I’m trying to obtain the currently set audio clip. No matter what I try, I’m unable to obtain it. I’m trying using:
private var defaultClip= Audio.clip;
Which is supposed to retrieve the currently set clip. What is the actual line of code I need to type in order to do that.
As a reference, I’m trying to make it to where when I enter in and out of a place it sets the clip to one specific to that area, but when you leave back to the regular area, it reinstates the initial clip.
Thanks in advance.
audio.clip, not Audio.clip (audio refers to the AudioSource component, Audio refers to the class, in general).
Sorry, that’s what I meant. Yea, it doesn’t work. I keep getting
UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.
If you are using C# don’t use this function in the constructor or field initializers, Instead move initialization to the Awake or Start function.
I’m using javascript.
Odd, but that’s what you have to do
(Unity is strange, sometimes).
private var defaultClip : AudioClip;
function Awake ()
{
defaultClip = audio.clip;
}