Skip to content

Commit

Permalink
Added fireball particle sound, fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
ddabble committed Feb 21, 2018
1 parent 703cd47 commit f4accb6
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 33 deletions.
84 changes: 83 additions & 1 deletion Assets/MagicBook/Prefabs/Spells/Fireball/FireRange.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions Assets/MagicBook/Scripts/Spells/Fireball/Fireball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -102,11 +98,13 @@ void OnTriggerEnter(Collider collider)
Destroy(gameObject);
}
}*/
var fireRange = Instantiate(FireRangePrefab);
PlayImpactSound();

FireballRange fireRange = Instantiate(FireRangePrefab).GetComponent<FireballRange>();
fireRange.transform.localScale *= damageRadius;
fireRange.GetComponent<FireballRange>().attackDamage = damage;
fireRange.attackDamage = damage;
fireRange.transform.position = transform.position;
PlayImpactSound();

//print("damage:" + damage.ToString());
//print("radius:" + damageRadius.ToString());
Destroy(gameObject);
Expand Down
69 changes: 46 additions & 23 deletions Assets/MagicBook/Scripts/Spells/Fireball/FireballRange.cs
Original file line number Diff line number Diff line change
@@ -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<ParticleSystem>();
ps.Stop();
var main = fireEffect.GetComponent<ParticleSystem>().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>();
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<SphereCollider>();

AudioSource audio = GetComponent<AudioSource>();
audio.clip = burnSound;
audio.Play();

StartCoroutine(Chronology());
}

Expand All @@ -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<SphereCollider>().enabled = false;
/*Color c = fireEffect.material.GetColor("_TintColor"); //make the object fade object by turning down its opacity gradually
while (c.a > 0)
{
Expand All @@ -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<AudioSource>();
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);
}
}
2 changes: 1 addition & 1 deletion Assets/Prefabs/Sound/PointSound.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ AudioSource:
Priority: 128
DopplerLevel: 1
MinDistance: 5
MaxDistance: 40
MaxDistance: 60
Pan2D: 0
rolloffMode: 1
BypassEffects: 0
Expand Down

0 comments on commit f4accb6

Please sign in to comment.