diff --git a/Assets/Audio/SFX/zombie1.ogg b/Assets/Audio/SFX/zombie1.ogg new file mode 100644 index 0000000..8abdc77 Binary files /dev/null and b/Assets/Audio/SFX/zombie1.ogg differ diff --git a/Assets/Audio/SFX/zombie1.ogg.meta b/Assets/Audio/SFX/zombie1.ogg.meta new file mode 100644 index 0000000..e73035d --- /dev/null +++ b/Assets/Audio/SFX/zombie1.ogg.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: f5ad48521bc6e104b91b244b73c17c2b +AudioImporter: + externalObjects: {} + serializedVersion: 8 + 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/Audio/SFX/zombie2.ogg b/Assets/Audio/SFX/zombie2.ogg new file mode 100644 index 0000000..031a5de Binary files /dev/null and b/Assets/Audio/SFX/zombie2.ogg differ diff --git a/Assets/Audio/SFX/zombie2.ogg.meta b/Assets/Audio/SFX/zombie2.ogg.meta new file mode 100644 index 0000000..f3b5214 --- /dev/null +++ b/Assets/Audio/SFX/zombie2.ogg.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 1e52096c131bbbb4f94236be610dbb22 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + 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/Audio/SFX/zombie3.ogg b/Assets/Audio/SFX/zombie3.ogg new file mode 100644 index 0000000..b53a6a7 Binary files /dev/null and b/Assets/Audio/SFX/zombie3.ogg differ diff --git a/Assets/Audio/SFX/zombie3.ogg.meta b/Assets/Audio/SFX/zombie3.ogg.meta new file mode 100644 index 0000000..11bc051 --- /dev/null +++ b/Assets/Audio/SFX/zombie3.ogg.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: a6d7ea851c2ca764a829054b971cfe67 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + 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/Audio/SFX/zombie4.ogg b/Assets/Audio/SFX/zombie4.ogg new file mode 100644 index 0000000..b506fe9 Binary files /dev/null and b/Assets/Audio/SFX/zombie4.ogg differ diff --git a/Assets/Audio/SFX/zombie4.ogg.meta b/Assets/Audio/SFX/zombie4.ogg.meta new file mode 100644 index 0000000..7f271da --- /dev/null +++ b/Assets/Audio/SFX/zombie4.ogg.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 98cbf8c7e7fb89345a25a8606b4761eb +AudioImporter: + externalObjects: {} + serializedVersion: 8 + 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/Prefabs/Zombie1.prefab b/Assets/Prefabs/Zombie1.prefab index 4364cbe..453a06c 100644 --- a/Assets/Prefabs/Zombie1.prefab +++ b/Assets/Prefabs/Zombie1.prefab @@ -1780,6 +1780,7 @@ GameObject: - component: {fileID: 2441744333336506289} - component: {fileID: 5950679062911607196} - component: {fileID: -7112169132516269854} + - component: {fileID: 8752207854750903613} m_Layer: 0 m_Name: Zombie1 m_TagString: Zombie @@ -1899,6 +1900,108 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9e6afdd2619c6db4e9c079733c664364, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::ZombieController + sfx: + - {fileID: 8300000, guid: f5ad48521bc6e104b91b244b73c17c2b, type: 3} + - {fileID: 8300000, guid: 1e52096c131bbbb4f94236be610dbb22, type: 3} + - {fileID: 8300000, guid: a6d7ea851c2ca764a829054b971cfe67, type: 3} + - {fileID: 8300000, guid: 98cbf8c7e7fb89345a25a8606b4761eb, type: 3} +--- !u!82 &8752207854750903613 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4493914613880827488} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_Resource: {fileID: 0} + m_PlayOnAwake: 0 + m_Volume: 1 + m_Pitch: 1 + Loop: 0 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &4710940672626480558 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/ZombieController.cs b/Assets/Scripts/ZombieController.cs index 7f64daa..74cb1bf 100644 --- a/Assets/Scripts/ZombieController.cs +++ b/Assets/Scripts/ZombieController.cs @@ -1,8 +1,8 @@ -using NUnit.Framework; using UnityEngine; [RequireComponent(typeof(Animator))] [RequireComponent(typeof(Rigidbody))] +[RequireComponent(typeof(AudioSource))] public class ZombieController : MonoBehaviour { private static readonly int DieHash = Animator.StringToHash("Die"); @@ -25,8 +25,14 @@ public class ZombieController : MonoBehaviour private readonly float attackCooldown = 1f; private float lastAttackTime; + [Header("Sounds")] + [SerializeField] private AudioClip[] sfx; + [SerializeField] private int sfxDelay = 5; // seconds + private Transform player; private Animator animator; + private AudioSource audioSource; + private float lastSfxPlay; private bool IsDead() => currentHealth == 0; @@ -35,12 +41,15 @@ public class ZombieController : MonoBehaviour currentHealth = maxHealth; animator = GetComponent(); player = GameObject.FindGameObjectWithTag("Player").transform; + audioSource = GetComponent(); } private void Update() { if (IsDead()) return; + PlaySfx(); + float distance = Vector3.Distance(transform.position, player.position); if (distance <= attackDistance) @@ -64,6 +73,23 @@ public class ZombieController : MonoBehaviour } } + private AudioClip PickSfx() + { + return sfx[UnityEngine.Random.Range(0, sfx.Length)]; + } + + private void PlaySfx() + { + if (Time.time - lastSfxPlay <= sfxDelay) + { + return; + } + + var clip = PickSfx(); + audioSource.PlayOneShot(clip); + lastSfxPlay = Time.time; + } + private void MoveToPlayer(float speed) { Vector3 direction = (player.position - transform.position).normalized;