added footsteps!

need to move the call from OnMove to Run, still some bugfixing to do
This commit is contained in:
Sam
2023-05-01 14:22:46 -07:00
parent 58222ed569
commit d2d10f064b
5 changed files with 67 additions and 6 deletions

View File

@@ -29,12 +29,22 @@ public class PlayerBehavior : MonoBehaviour
Animator animator;
[HideInInspector] public bool playerIsAlive = true;
[Header("Sound")]
[SerializeField] public AudioClip footstepSound;
[SerializeField] public AudioClip deathSound;
AudioSource audioSource;
void Start()
{
{ // initialize
_rb = GetComponent<Rigidbody2D>();
stateController = GameObject.Find("StateController").GetComponent<StateController>();
audioSource = this.gameObject.GetComponent<AudioSource>();
audioSource.clip = footstepSound;
audioSource.loop = true;
animator = GetComponent<Animator>();
GameObject.Find("Main Camera").GetComponent<CameraMovement>().player = this.gameObject;
playerIsAlive = true;
@@ -204,13 +214,14 @@ public class PlayerBehavior : MonoBehaviour
if (playerIsAlive) {
print("destroyPlayer called");
playerIsAlive = false;
AudioSource audio = this.gameObject.GetComponent<AudioSource>();
audio.Play();
audioSource.clip = deathSound;
audioSource.loop = false;
audioSource.Play();
// animate
animator.Play("Die");
// yield return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);
yield return new WaitForSeconds(audio.clip.length);
yield return new WaitForSeconds(audioSource.clip.length);
// this.stateController.SetDeathCanvasActive(true);