-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.wav filter=lfs diff=lfs merge=lfs -text |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class AudioController : MonoBehaviour { | ||
public AudioClip[] ambientSounds; | ||
public AudioClip[] stepSounds; | ||
public AudioClip[] harvestSounds; | ||
|
||
private AudioSource audioSource; | ||
|
||
private float _stepSoundTimer = 0f; | ||
private float _stepSoundDelay = 0.6f; | ||
|
||
void Start() { | ||
audioSource = GetComponent<AudioSource>(); | ||
PlayAmbientSound(); | ||
} | ||
|
||
void Update() { | ||
// TODO: Change ambient theme based on time of day | ||
} | ||
|
||
public void PlayStepSound() { | ||
int index = Random.Range(0, stepSounds.Length); | ||
audioSource.PlayOneShot(stepSounds[index]); | ||
} | ||
|
||
public void HandleStepSounds(bool isMoving) { | ||
if (isMoving) { | ||
_stepSoundTimer += Time.deltaTime; | ||
if (_stepSoundTimer >= _stepSoundDelay) { | ||
PlayStepSound(); | ||
_stepSoundTimer = 0f; | ||
} | ||
} else { | ||
_stepSoundTimer = 0f; | ||
} | ||
} | ||
|
||
public void PlayHarvestSound(float delay = 0f) { | ||
StartCoroutine(PlayHarvestSoundWithDelay(delay)); | ||
} | ||
|
||
private IEnumerator PlayHarvestSoundWithDelay(float delay) { | ||
yield return new WaitForSeconds(delay); | ||
int index = Random.Range(0, harvestSounds.Length); | ||
audioSource.PlayOneShot(harvestSounds[index]); | ||
} | ||
|
||
public void PlayAmbientSound() { | ||
int index = Random.Range(0, ambientSounds.Length); | ||
audioSource.PlayOneShot(ambientSounds[index]); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.