diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 47d2f2f..f7f292d 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -370,6 +370,8 @@ MonoBehaviour: playerController: {fileID: 5559747613460074786} stateController: {fileID: 0} playerIsAlive: 1 + footstepSound: {fileID: 8300000, guid: 229b1f1bff3f442ef84c0c9b767dda07, type: 3} + deathSound: {fileID: 8300000, guid: 3498b07b14bc248cdbc50aa434f962c2, type: 3} --- !u!114 &5559747613460074786 MonoBehaviour: m_ObjectHideFlags: 0 @@ -468,11 +470,11 @@ AudioSource: m_Enabled: 1 serializedVersion: 4 OutputAudioMixerGroup: {fileID: 0} - m_audioClip: {fileID: 8300000, guid: 3498b07b14bc248cdbc50aa434f962c2, type: 3} + m_audioClip: {fileID: 8300000, guid: 229b1f1bff3f442ef84c0c9b767dda07, type: 3} m_PlayOnAwake: 0 m_Volume: 1 m_Pitch: 1 - Loop: 0 + Loop: 1 Mute: 0 Spatialize: 0 SpatializePostEffects: 0 diff --git a/Assets/SFX/footsteps.wav b/Assets/SFX/footsteps.wav new file mode 100644 index 0000000..a6f29ff Binary files /dev/null and b/Assets/SFX/footsteps.wav differ diff --git a/Assets/SFX/footsteps.wav.meta b/Assets/SFX/footsteps.wav.meta new file mode 100644 index 0000000..6f062e6 --- /dev/null +++ b/Assets/SFX/footsteps.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 229b1f1bff3f442ef84c0c9b767dda07 +AudioImporter: + externalObjects: {} + serializedVersion: 7 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerBehavior.cs b/Assets/Scripts/PlayerBehavior.cs index 1f8f120..58aabbd 100644 --- a/Assets/Scripts/PlayerBehavior.cs +++ b/Assets/Scripts/PlayerBehavior.cs @@ -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(); stateController = GameObject.Find("StateController").GetComponent(); + + audioSource = this.gameObject.GetComponent(); + audioSource.clip = footstepSound; + audioSource.loop = true; + animator = GetComponent(); GameObject.Find("Main Camera").GetComponent().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(); - 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); diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 1058eee..ebd6f91 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -63,6 +63,9 @@ public class PlayerMovement : MonoBehaviour [HideInInspector] private PlayerBehavior playerBehavior; [HideInInspector] private StateController stateController; + + [HideInInspector] private AudioSource audioSource; + [HideInInspector] private bool soundPlaying = false; #endregion private void Awake() @@ -71,6 +74,7 @@ public class PlayerMovement : MonoBehaviour playerBehavior = this.gameObject.GetComponent(); grapplingRope = playerBehavior.grapplingRope; stateController = GameObject.FindGameObjectWithTag("StateController").GetComponent(); + audioSource = GetComponent(); } private void Start() @@ -86,6 +90,18 @@ public class PlayerMovement : MonoBehaviour } else { this._moveInput = Vector2.zero; } + + if (!IsJumping && !_isJumpFalling && !isRegFalling && value.Get().x != 0) { + if (!soundPlaying) { + print("footsteps PLAY"); + audioSource.Play(); + soundPlaying = true; + } + } else if (audioSource.isPlaying && audioSource.clip.name == "footsteps") { + print("footsteps stop"); + audioSource.Stop(); + soundPlaying = false; + } } void OnJump() @@ -364,6 +380,15 @@ public class PlayerMovement : MonoBehaviour //Convert this to a vector and apply to rigidbody RB.AddForce(movement * Vector2.right, ForceMode2D.Force); + // play sound + // if (!IsJumping && movement != 0) { + // if (!audioSource.isPlaying) { + // audioSource.Play(); + // } + // } else if (audioSource.isPlaying && audioSource.clip.name == "footsteps") { + // audioSource.Stop(); + // } + /* * For those interested here is what AddForce() will do * RB.velocity = new Vector2(RB.velocity.x + (Time.fixedDeltaTime * speedDif * accelRate) / RB.mass, RB.velocity.y);