58 lines
No EOL
993 B
C#
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
|
|
}
|
|
} |