added footsteps!
need to move the call from OnMove to Run, still some bugfixing to do
This commit is contained in:
parent
58222ed569
commit
d2d10f064b
@ -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
|
||||
|
BIN
Assets/SFX/footsteps.wav
Normal file
BIN
Assets/SFX/footsteps.wav
Normal file
Binary file not shown.
23
Assets/SFX/footsteps.wav.meta
Normal file
23
Assets/SFX/footsteps.wav.meta
Normal 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:
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user