From e1ccd7f8fff0ab9faa0adeaf3314413445c008a1 Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Sun, 21 Apr 2024 06:59:36 +0200 Subject: [PATCH] music intesinity --- Assets/Prefabs/Managers.prefab | 50 ++++++++++++++++++++- Assets/Scripts/Camera/HideWall.cs | 1 + Assets/Scripts/Manager/MusicManager.cs | 38 ++++++++++++++++ Assets/Scripts/Manager/MusicManager.cs.meta | 11 +++++ 4 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 Assets/Scripts/Manager/MusicManager.cs create mode 100644 Assets/Scripts/Manager/MusicManager.cs.meta diff --git a/Assets/Prefabs/Managers.prefab b/Assets/Prefabs/Managers.prefab index 9dff6ef..200d432 100644 --- a/Assets/Prefabs/Managers.prefab +++ b/Assets/Prefabs/Managers.prefab @@ -12,6 +12,7 @@ GameObject: - component: {fileID: 420908950823711560} - component: {fileID: 6434302952035194364} - component: {fileID: 3776162552967268432} + - component: {fileID: 4575217513678934597} m_Layer: 0 m_Name: Managers m_TagString: Untagged @@ -46,7 +47,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 00e1f7ea5be7c564faf42d035aec7f53, type: 3} m_Name: m_EditorClassIdentifier: - Balance: 0 + Balance: + value: 500 + onValueChanged: + m_PersistentCalls: + m_Calls: [] IsBuildMode: 0 --- !u!114 &6434302952035194364 MonoBehaviour: @@ -73,8 +78,51 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f2cd736facf1d954d981c917c80d9c25, type: 3} m_Name: m_EditorClassIdentifier: + HasStarted: 0 IsAutoPlaying: 0 levelDefinition: {fileID: 11400000, guid: c8d456118a95ada459f30817ed2351a2, type: 2} enemyCollection: {fileID: 11400000, guid: d600de6e8946fe54db15d9208f6f63f5, type: 2} groundPath: {fileID: 0} skyPath: {fileID: 0} + PlayButton: {fileID: 0} + AutoPlayButton: {fileID: 0} +--- !u!114 &4575217513678934597 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 167310329963132665} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 39d50303aa616fba99c8ad2b1addfb21, type: 3} + m_Name: + m_EditorClassIdentifier: + projectilesToIntensity: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0.06666667 + outSlope: 0.06666667 + tangentMode: 34 + weightedMode: 0 + inWeight: 0 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 30 + value: 3 + inSlope: 0.06666667 + outSlope: 0.06666667 + tangentMode: 34 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + intensities: + - {fileID: 8300000, guid: 8e038767673552d4fb9f6e5927df20b2, type: 3} + - {fileID: 8300000, guid: c37548871dcc24746aef5f5f5d248453, type: 3} + - {fileID: 8300000, guid: d0fe8353aa0b5024699b5632cb56d98f, type: 3} diff --git a/Assets/Scripts/Camera/HideWall.cs b/Assets/Scripts/Camera/HideWall.cs index 41a2e97..d9a4d1a 100644 --- a/Assets/Scripts/Camera/HideWall.cs +++ b/Assets/Scripts/Camera/HideWall.cs @@ -51,6 +51,7 @@ public class HideWall : MonoBehaviour foreach (var prevHitObject in prevHitObjects) { + if (prevHitObject == null) break; if (!hitObjectsThisFrame.Contains(prevHitObject)) { var wallOpacity = prevHitObject.GetComponent(); diff --git a/Assets/Scripts/Manager/MusicManager.cs b/Assets/Scripts/Manager/MusicManager.cs new file mode 100644 index 0000000..c626d89 --- /dev/null +++ b/Assets/Scripts/Manager/MusicManager.cs @@ -0,0 +1,38 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MusicManager : MonoBehaviour +{ + [SerializeField] AnimationCurve projectilesToIntensity; + + [SerializeField] + AudioClip[] intensities; + + private int prevIntinsity = -1; + + private AudioSource[] sources; + + void Awake() + { + sources = new AudioSource[intensities.Length]; + } + + private void Update() + { + int projectileCount = GameObject.FindObjectsByType(FindObjectsSortMode.None).Length; + int intensity = (int) projectilesToIntensity.Evaluate(projectileCount) - 1; + + if (intensity > prevIntinsity) + { + sources[intensity] = AudioManager.PlaySound(intensities[intensity], Vector3.zero, false, false, true, true); + } + else if (intensity < prevIntinsity) + { + if (sources[prevIntinsity] != null) + sources[prevIntinsity].Stop(); + } + + prevIntinsity = intensity; + } +} diff --git a/Assets/Scripts/Manager/MusicManager.cs.meta b/Assets/Scripts/Manager/MusicManager.cs.meta new file mode 100644 index 0000000..ec37f4d --- /dev/null +++ b/Assets/Scripts/Manager/MusicManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 39d50303aa616fba99c8ad2b1addfb21 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: