From f4accb6ebd69c3064aa26f34bacd8fa670f04913 Mon Sep 17 00:00:00 2001 From: Dabble Date: Wed, 21 Feb 2018 03:10:57 +0100 Subject: [PATCH] Added fireball particle sound, fixes #33 --- .../Prefabs/Spells/Fireball/FireRange.prefab | 84 ++++++++++++++++++- .../Spells/Fireball/FireballEffect.prefab | 2 +- .../Scripts/Spells/Fireball/Fireball.cs | 12 ++- .../Scripts/Spells/Fireball/FireballRange.cs | 69 ++++++++++----- Assets/Prefabs/Sound/PointSound.prefab | 2 +- 5 files changed, 136 insertions(+), 33 deletions(-) diff --git a/Assets/MagicBook/Prefabs/Spells/Fireball/FireRange.prefab b/Assets/MagicBook/Prefabs/Spells/Fireball/FireRange.prefab index 1f5f2f6b..4145a4e1 100644 --- a/Assets/MagicBook/Prefabs/Spells/Fireball/FireRange.prefab +++ b/Assets/MagicBook/Prefabs/Spells/Fireball/FireRange.prefab @@ -19,9 +19,9 @@ GameObject: serializedVersion: 5 m_Component: - component: {fileID: 4564571685921780} + - component: {fileID: 114454205553294542} - component: {fileID: 198605923375661428} - component: {fileID: 199894523801454330} - - component: {fileID: 114454205553294542} m_Layer: 0 m_Name: FireballEffect m_TagString: Untagged @@ -58,6 +58,7 @@ GameObject: - component: {fileID: 135792272438208660} - component: {fileID: 114881982142788198} - component: {fileID: 114492050305786506} + - component: {fileID: 82820574358528774} m_Layer: 0 m_Name: FireRange m_TagString: Untagged @@ -182,6 +183,86 @@ Rigidbody: m_Interpolate: 0 m_Constraints: 0 m_CollisionDetection: 0 +--- !u!82 &82820574358528774 +AudioSource: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 1673509378881658} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 0} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 1 + 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: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + - serializedVersion: 2 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 0 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 0 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 2 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 0 --- !u!108 &108510450640879006 Light: m_ObjectHideFlags: 1 @@ -253,6 +334,7 @@ MonoBehaviour: m_EditorClassIdentifier: fireEffect: {fileID: 199894523801454330} smokeEffect: {fileID: 198456965011063730} + burnSound: {fileID: 8300000, guid: 6f90190451d454f5db5f6e71862cdeb1, type: 3} attackDamage: 0 totalBurnDuration: 3 --- !u!135 &135792272438208660 diff --git a/Assets/MagicBook/Prefabs/Spells/Fireball/FireballEffect.prefab b/Assets/MagicBook/Prefabs/Spells/Fireball/FireballEffect.prefab index 46fd4add..fdef092f 100644 --- a/Assets/MagicBook/Prefabs/Spells/Fireball/FireballEffect.prefab +++ b/Assets/MagicBook/Prefabs/Spells/Fireball/FireballEffect.prefab @@ -19,9 +19,9 @@ GameObject: serializedVersion: 5 m_Component: - component: {fileID: 4113095535572826} + - component: {fileID: 114107097949485434} - component: {fileID: 198342620694680766} - component: {fileID: 199893699604099760} - - component: {fileID: 114107097949485434} m_Layer: 0 m_Name: FireballEffect m_TagString: Untagged diff --git a/Assets/MagicBook/Scripts/Spells/Fireball/Fireball.cs b/Assets/MagicBook/Scripts/Spells/Fireball/Fireball.cs index ee4fcd2d..fa17c845 100644 --- a/Assets/MagicBook/Scripts/Spells/Fireball/Fireball.cs +++ b/Assets/MagicBook/Scripts/Spells/Fireball/Fireball.cs @@ -14,16 +14,12 @@ public class Fireball : Spell private float maxAdditionalDamageRadius = 3f; #region ParticleSystem - public ParticleSystem ps; - //private float targetStartSize; - private float maxScaleMultiplier = 7.1f; //double the size of fireball; private Vector3 maxAdditionalScale; #endregion protected override void Start_Derived() { - //targetStartSize = ps.main.startSize.constant; maxAdditionalScale = transform.lossyScale * maxScaleMultiplier; StartCoroutine(Show()); } @@ -102,11 +98,13 @@ void OnTriggerEnter(Collider collider) Destroy(gameObject); } }*/ - var fireRange = Instantiate(FireRangePrefab); + PlayImpactSound(); + + FireballRange fireRange = Instantiate(FireRangePrefab).GetComponent(); fireRange.transform.localScale *= damageRadius; - fireRange.GetComponent().attackDamage = damage; + fireRange.attackDamage = damage; fireRange.transform.position = transform.position; - PlayImpactSound(); + //print("damage:" + damage.ToString()); //print("radius:" + damageRadius.ToString()); Destroy(gameObject); diff --git a/Assets/MagicBook/Scripts/Spells/Fireball/FireballRange.cs b/Assets/MagicBook/Scripts/Spells/Fireball/FireballRange.cs index 6d39b417..be0a1e51 100644 --- a/Assets/MagicBook/Scripts/Spells/Fireball/FireballRange.cs +++ b/Assets/MagicBook/Scripts/Spells/Fireball/FireballRange.cs @@ -1,34 +1,42 @@ using System.Collections; -using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(SphereCollider))] public class FireballRange : MonoBehaviour { - private SphereCollider sCol; - public ParticleSystemRenderer fireEffect; public ParticleSystem smokeEffect; + + public AudioClip burnSound; + public float attackDamage; // per second public float totalBurnDuration; //slow for seconds + private float particleLifetime; + void Start() { #region changeDurationOfParticleSystems - var ps = fireEffect.GetComponent(); - ps.Stop(); - var main = fireEffect.GetComponent().main; - main.duration = totalBurnDuration; - ps.Play(); - smokeEffect.Stop(); - main = smokeEffect.main; - if (totalBurnDuration < 1) - main.duration = 0.01f; - else - main.duration = totalBurnDuration - 1f; - smokeEffect.Play(); + ParticleSystem particleSystem = fireEffect.GetComponent(); + ParticleSystem.MainModule main = particleSystem.main; + particleLifetime = main.startLifetime.constant; + + particleSystem.Stop(); + main.duration = totalBurnDuration; + particleSystem.Play(); + smokeEffect.Stop(); + main = smokeEffect.main; + if (totalBurnDuration < particleLifetime) + main.duration = 0.01f; + else + main.duration = totalBurnDuration - particleLifetime; + smokeEffect.Play(); #endregion - sCol = GetComponent(); + + AudioSource audio = GetComponent(); + audio.clip = burnSound; + audio.Play(); + StartCoroutine(Chronology()); } @@ -41,12 +49,15 @@ void OnTriggerStay(Collider col) } } - private IEnumerator Chronology() { - yield return new WaitForSeconds(totalBurnDuration + 1f); //1f is the life time of each particle + yield return new WaitForSeconds(totalBurnDuration); + + StartCoroutine(FadeAudio(particleLifetime)); + yield return new WaitForSeconds(particleLifetime); + //remove the AOE - sCol.enabled = false; + GetComponent().enabled = false; /*Color c = fireEffect.material.GetColor("_TintColor"); //make the object fade object by turning down its opacity gradually while (c.a > 0) { @@ -57,16 +68,28 @@ private IEnumerator Chronology() yield return null; }*/ - //make the fire transparent and remove it - //wait till the smoke disappears - yield return new WaitForSeconds(3f); + yield return new WaitForSeconds(smokeEffect.main.duration); Destroy(gameObject); } + private IEnumerator FadeAudio(float fadeTime) + { + AudioSource audio = GetComponent(); + float startVolume = audio.volume; + + while (audio.volume > 0) + { + audio.volume -= startVolume * Time.deltaTime / fadeTime; + yield return null; + } + + audio.Stop(); + } + void InflictDamage(Enemy enemy) { - enemy.InflictDamage(attackDamage*Time.deltaTime); + enemy.InflictDamage(attackDamage * Time.deltaTime); } } diff --git a/Assets/Prefabs/Sound/PointSound.prefab b/Assets/Prefabs/Sound/PointSound.prefab index a7120983..15e4358e 100644 --- a/Assets/Prefabs/Sound/PointSound.prefab +++ b/Assets/Prefabs/Sound/PointSound.prefab @@ -60,7 +60,7 @@ AudioSource: Priority: 128 DopplerLevel: 1 MinDistance: 5 - MaxDistance: 40 + MaxDistance: 60 Pan2D: 0 rolloffMode: 1 BypassEffects: 0