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

@ -370,6 +370,8 @@ MonoBehaviour:
playerController: {fileID: 5559747613460074786} playerController: {fileID: 5559747613460074786}
stateController: {fileID: 0} stateController: {fileID: 0}
playerIsAlive: 1 playerIsAlive: 1
footstepSound: {fileID: 8300000, guid: 229b1f1bff3f442ef84c0c9b767dda07, type: 3}
deathSound: {fileID: 8300000, guid: 3498b07b14bc248cdbc50aa434f962c2, type: 3}
--- !u!114 &5559747613460074786 --- !u!114 &5559747613460074786
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -468,11 +470,11 @@ AudioSource:
m_Enabled: 1 m_Enabled: 1
serializedVersion: 4 serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0} OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 3498b07b14bc248cdbc50aa434f962c2, type: 3} m_audioClip: {fileID: 8300000, guid: 229b1f1bff3f442ef84c0c9b767dda07, type: 3}
m_PlayOnAwake: 0 m_PlayOnAwake: 0
m_Volume: 1 m_Volume: 1
m_Pitch: 1 m_Pitch: 1
Loop: 0 Loop: 1
Mute: 0 Mute: 0
Spatialize: 0 Spatialize: 0
SpatializePostEffects: 0 SpatializePostEffects: 0

BIN
Assets/SFX/footsteps.wav Normal file

Binary file not shown.

View File

@ -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:

View File

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

View File

@ -63,6 +63,9 @@ public class PlayerMovement : MonoBehaviour
[HideInInspector] private PlayerBehavior playerBehavior; [HideInInspector] private PlayerBehavior playerBehavior;
[HideInInspector] private StateController stateController; [HideInInspector] private StateController stateController;
[HideInInspector] private AudioSource audioSource;
[HideInInspector] private bool soundPlaying = false;
#endregion #endregion
private void Awake() private void Awake()
@ -71,6 +74,7 @@ public class PlayerMovement : MonoBehaviour
playerBehavior = this.gameObject.GetComponent<PlayerBehavior>(); playerBehavior = this.gameObject.GetComponent<PlayerBehavior>();
grapplingRope = playerBehavior.grapplingRope; grapplingRope = playerBehavior.grapplingRope;
stateController = GameObject.FindGameObjectWithTag("StateController").GetComponent<StateController>(); stateController = GameObject.FindGameObjectWithTag("StateController").GetComponent<StateController>();
audioSource = GetComponent<AudioSource>();
} }
private void Start() private void Start()
@ -86,6 +90,18 @@ public class PlayerMovement : MonoBehaviour
} else { } else {
this._moveInput = Vector2.zero; this._moveInput = Vector2.zero;
} }
if (!IsJumping && !_isJumpFalling && !isRegFalling && value.Get<Vector2>().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() void OnJump()
@ -364,6 +380,15 @@ public class PlayerMovement : MonoBehaviour
//Convert this to a vector and apply to rigidbody //Convert this to a vector and apply to rigidbody
RB.AddForce(movement * Vector2.right, ForceMode2D.Force); 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 * 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); * RB.velocity = new Vector2(RB.velocity.x + (Time.fixedDeltaTime * speedDif * accelRate) / RB.mass, RB.velocity.y);