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

@@ -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<PlayerBehavior>();
grapplingRope = playerBehavior.grapplingRope;
stateController = GameObject.FindGameObjectWithTag("StateController").GetComponent<StateController>();
audioSource = GetComponent<AudioSource>();
}
private void Start()
@@ -86,6 +90,18 @@ public class PlayerMovement : MonoBehaviour
} else {
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()
@@ -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);