Basically, I had an two arrays that I initialized outside of a function and I got the error :
"field initializer cannot reference the nonstatic field, method, or property… ".
Everything else was fine. I moved the initialization into my Start function, and now I have the error
“The name `audioArray’ does not exist in the current context”.
I’ve checked for a typo, but I doubt it since that was fine before I moved it to Start (). I’m probably missing something big.
void Start () {
AudioSource[] audioArray = {audioFloat1, audioFloat2, audioFloat3};
AudioClip[] clipArray = {clipFloat1, clipFloat2, clipFloat3};
}
void playRandom(){
int clipPick = Random.Range(0, audioArray.Length); //audioArray is displayed in red
audioArray[clipPick].PlayOneShot (clipArray[clipPick]); //audioArray and clipArray are displayed in red
}
It’s the first time I have that problem without seeing what’s wrong and I’m really confused… Can you help me ?
Any help is appreciated