diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index dbb4bda2fde991e2cb3dd32c2305f7cba590e6e3..5e263ce6a53557b1e19921c2b2b7cbc0a062afa6 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -18,7 +18,7 @@ namespace BigSock { public float AttackSpeed => Stats.AttackSpeed; public float baseAttackSpeed = 1; - public AudioSource[] source; + public List<AudioSource> source = new List<AudioSource>(); public AudioClip TakeDamageAudio; /* @@ -101,8 +101,7 @@ namespace BigSock { */ public ICharacterStats Stats { get; protected set; } = new CharacterStats(); - public Character() - { + public Character() { Inventory = new Inventory(this); Inventory.BackpackCap = 5; } @@ -131,8 +130,14 @@ namespace BigSock { Accuracy = 1, }; - source = Camera.main.gameObject.GetComponents<AudioSource>(); - + // Add audio sources. + foreach(var s in Camera.main.gameObject.GetComponents<AudioSource>()) + if(s != null) + source.Add(s); + + var src = GetComponent<AudioSource>(); + if(src != null) source.Add(src); + UpdateModifiers(); diff --git a/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs index 2228aa80d7bbd85693a3db662ec4de42398e0747..505c9dc1032e4e731a18029ac9d725032a682a21 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs @@ -1,6 +1,7 @@ using System.Collections; using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; using UnityEngine.InputSystem; @@ -60,7 +61,7 @@ namespace BigSock { bulletScript.Direction = (target.Value - (Vector2) actor.transform.position).normalized; // Play sound effect - var source = actor.source[0]; + var source = actor.source.FirstOrDefault(); var audioClip = AudioService.SINGLETON.Get(AUDIO_PATH); if (source != null && audioClip != null) { source.clip = audioClip; diff --git a/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile2.cs b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile2.cs index d17b36feec45a29709a3ce9bbd7167539cac63a1..03ec41247beed2eefcd2a50d33089c6eabc4634e 100644 --- a/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile2.cs +++ b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile2.cs @@ -1,6 +1,7 @@ using System.Collections; using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; using UnityEngine.InputSystem; @@ -74,7 +75,7 @@ namespace BigSock { bulletScript.Direction = (target.Value - (Vector2) actor.transform.position).normalized; // Play sound effect - var source = actor.source; + var source = actor.source.FirstOrDefault(); var audioClip = AudioService.SINGLETON.Get(AUDIO_PATH); if (source != null && audioClip != null) { source.clip = audioClip;