From 4a4c95d3027ea467488644c21da205a841f66dd3 Mon Sep 17 00:00:00 2001 From: Yann Dupont 01 Date: Sun, 3 Apr 2022 18:07:43 -0400 Subject: [PATCH] Jump/land SFX --- Assets/Prefabs/Vampire.prefab | 143 +++++++++++++++++++++++++++++++ Assets/Scripts/PlayerMovement.cs | 11 ++- 2 files changed, 153 insertions(+), 1 deletion(-) diff --git a/Assets/Prefabs/Vampire.prefab b/Assets/Prefabs/Vampire.prefab index 8214fce..7f20780 100644 --- a/Assets/Prefabs/Vampire.prefab +++ b/Assets/Prefabs/Vampire.prefab @@ -58,6 +58,13 @@ MonoBehaviour: gameFlowManager: {fileID: 0} stats: {fileID: 11400000, guid: 12a626b5a296d934ba078d222ad6ba98, type: 2} globalCamera: {fileID: 0} + jumpSource: {fileID: 7164870411903264125} + jumpSounds: + - {fileID: 8300000, guid: 2f93dc5371f10744ba49e29576e8a6a7, type: 3} + landSource: {fileID: 5290033541484811060} + landSounds: + - {fileID: 8300000, guid: 1376bbb24def5184393e893817fe41ca, type: 3} + soundManager: {fileID: 0} --- !u!114 &3126145803593047825 MonoBehaviour: m_ObjectHideFlags: 0 @@ -409,6 +416,8 @@ Transform: - {fileID: 8766613565529140840} - {fileID: 6919064404994049919} - {fileID: 7801168753088406092} + - {fileID: 4502282848150149069} + - {fileID: 1476073137437876612} m_Father: {fileID: 1214567908930553594} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -709,6 +718,73 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!1001 &1478865402374041860 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 903222670005920393} + m_Modifications: + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_RootOrder + value: 5 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6915619910278317271, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_Name + value: Land Source + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} +--- !u!4 &1476073137437876612 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + m_PrefabInstance: {fileID: 1478865402374041860} + m_PrefabAsset: {fileID: 0} +--- !u!82 &5290033541484811060 stripped +AudioSource: + m_CorrespondingSourceObject: {fileID: 6767790137851257392, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + m_PrefabInstance: {fileID: 1478865402374041860} + m_PrefabAsset: {fileID: 0} --- !u!1001 &3643467873725871148 PrefabInstance: m_ObjectHideFlags: 0 @@ -776,6 +852,73 @@ AudioSource: m_CorrespondingSourceObject: {fileID: 6767790137851257392, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} m_PrefabInstance: {fileID: 3643467873725871148} m_PrefabAsset: {fileID: 0} +--- !u!1001 &4504372482479179597 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 903222670005920393} + m_Modifications: + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_RootOrder + value: 4 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6915619910278317271, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + propertyPath: m_Name + value: Jump Source + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} +--- !u!82 &7164870411903264125 stripped +AudioSource: + m_CorrespondingSourceObject: {fileID: 6767790137851257392, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + m_PrefabInstance: {fileID: 4504372482479179597} + m_PrefabAsset: {fileID: 0} +--- !u!4 &4502282848150149069 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 70347360213241984, guid: 8929857cf558a9b40a30682dc94048ad, type: 3} + m_PrefabInstance: {fileID: 4504372482479179597} + m_PrefabAsset: {fileID: 0} --- !u!1001 &6988628843130902527 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs index 09d9b21..a31bf84 100644 --- a/Assets/Scripts/PlayerMovement.cs +++ b/Assets/Scripts/PlayerMovement.cs @@ -22,6 +22,12 @@ public class PlayerMovement : MonoBehaviour { Animator animator = null!; public bool facingRight { get; private set; } = true; + [SerializeField] AudioSource jumpSource; + [SerializeField] AudioClip[] jumpSounds; + [SerializeField] AudioSource landSource; + [SerializeField] AudioClip[] landSounds; + [HideInInspector] public SoundManager soundManager; + bool lastJumpButton; public bool IsInSafeZone => currentState is ImmobileMovementState; @@ -33,6 +39,7 @@ public class PlayerMovement : MonoBehaviour { vampireEntity = GetComponent(); animator = GetComponentInChildren(); currentState = new ImmobileMovementState(this); + soundManager = FindObjectOfType(); } void Start() { @@ -185,10 +192,12 @@ public class PlayerMovement : MonoBehaviour { startTime = Time.time; // playerMovement.animator.SetBool("Jumping", true); playerMovement.animator.Play("Player_Jump"); + playerMovement.soundManager.PlaySound(playerMovement.jumpSource, playerMovement.jumpSounds, randomPitch: true, createTempSourceIfBusy: true); } public override void LeaveState() { // playerMovement.animator.SetBool("Jumping", false); playerMovement.animator.Play("Player_Idle"); + playerMovement.soundManager.PlaySound(playerMovement.landSource, playerMovement.landSounds, randomPitch: true, createTempSourceIfBusy: true); } public override BaseState? FixedUpdateState() { @@ -236,7 +245,7 @@ public class PlayerMovement : MonoBehaviour { } public override void LeaveState() { - base.EnterState(); + base.LeaveState(); playerMovement.rb.SetEnabled(true); }