Game Development Reference
In-Depth Information
int i = 0;
atmList.Capacity = keys.Capacity;
foreach(AudioClip ac in tmpList)
{
atmList.Add(new KeyValuePair<string,
AudioClip>(keys[i], ac));
i++;
}
}
First, we assign the volume of AudioSource to our volume variable. Next, we cre-
ate an iterator for what we will do next. To assign our internal list, we set its capacity
equal to the capacity of the string list. Next, we run a foreach loop to check for
every AudioClip within the temporary list that we created earlier. Finally, for each
of the audio clips, we add a new KeyValuPair item, which includes the name that
we want to call within the code, and the associating AudioClip to it.
Playing the atmospheric sounds
We will create two possible ways to play our atmospheric sounds. First, we will allow
the sound to play and have it loop, which would be helpful for a rain sound effect or
wind sound effect. Add this function to your script:
void PlayRepeat(string atmSong)
{
for(int i = 0; i < atmList.Count; i++)
{
if(atmList[i].Key == atmSong)
{
audio.clip = atmList[i].Value;
break;
}
}
audio.loop = true;
Search WWH ::




Custom Search