Files
Darklings-FightingGame/Assets/_Project/Scripts/SoundScripts/SoundGroup.cs
2022-12-14 18:33:44 +02:00

37 lines
737 B
C#

using System;
[Serializable]
public class SoundGroup
{
public string name;
public int lastPlayedSoundIndex;
public Sound[] sounds;
public void PlayInOrder()
{
int index = lastPlayedSoundIndex;
sounds[index].source.Play();
lastPlayedSoundIndex++;
if (lastPlayedSoundIndex >= sounds.Length)
{
lastPlayedSoundIndex = 0;
}
}
public Sound PlayInRandom()
{
Sound randomSound = sounds[UnityEngine.Random.Range(0, sounds.Length)];
randomSound.source.Play();
return randomSound;
}
public Sound Sound(string name)
{
Sound sound = Array.Find(sounds, s => s.name == name);
return sound;
}
}