This repository has been archived on 2024-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
snakeinabox/Assets/Scripts/SFX.cs
2020-09-04 22:31:02 -07:00

58 lines
No EOL
993 B
C#

using UnityEngine;
public class SFX
{
public SFX(SoundData data)
{
Game.OnStep += this.SnakeStep;
Game.OnEat += this.Eat;
Game.OnBump += this.Bump;
Game.OnCrash += this.Crash;
this.data = data;
}
SoundData data;
// the only sfxs that are not step based is the UI
// same class different audioSources
void SnakeStep(int full)
{
data.PickClip(data.sfxSteps);
}
void Eat(Vector3 pos)
{
data.queuedClip = data.sfxEat;
}
void Bump(Vector3 dir)
{
data.PickClip(data.sfxBumps);
}
void Crash(Vector3 dir)
{
data.queuedClip = data.sfxCrash;
}
int oldGrowQueue;
public void Step(Main main)
{
// bump box
// if head pos hasb't changed in a step
// game over
// some bool? restart int?
if (data.queuedClip != null)
{
main.sfxSource.clip = data.queuedClip;
main.sfxSource.volume = data.sfxVolume;
main.sfxSource.Play();
}
data.queuedClip = null; // clear queue
}
}