Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added audio distortion when base is hit #67

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Assets/DistortOnDamage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DistortOnDamage : MonoBehaviour
{
public AnimationCurve distortCurve;
public float distortTime;
private AudioSource audio_source;

bool distorting = false;
void Start()
{
BaseController.Singleton.GetComponent<HealthLogic>().onDamage += (d) => distort();
audio_source = GetComponent<AudioSource>();
}

void distort()
{
if (!distorting)
{
StartCoroutine(DistortRoutine());
}
}

private IEnumerator DistortRoutine()
{
distorting = true;
float startTime = Time.time;
while (Time.time < startTime + distortTime)
{
audio_source.pitch = distortCurve.Evaluate((Time.time - startTime) / distortTime);
yield return null;
}
distorting = false;
}
}
11 changes: 11 additions & 0 deletions Assets/DistortOnDamage.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions Assets/Prefabs/Audio/AudioManager.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GameObject:
m_Component:
- component: {fileID: 6421725047126160681}
- component: {fileID: 6421725047126160680}
- component: {fileID: 4653917452071846527}
m_Layer: 0
m_Name: AudioManager
m_TagString: Untagged
Expand Down Expand Up @@ -127,3 +128,85 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!114 &4653917452071846527
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6421725047126160687}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d425046e64c0b584b95947c3ae77ccb0, type: 3}
m_Name:
m_EditorClassIdentifier:
distortCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 10.591079
outSlope: 10.591079
tangentMode: 34
weightedMode: 0
inWeight: 0
outWeight: 0.33333334
- serializedVersion: 3
time: 0.07069163
value: 1.7487006
inSlope: 1.2994882
outSlope: 1.2994882
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 1
- serializedVersion: 3
time: 0.1982835
value: 0.69611263
inSlope: 1.3349094
outSlope: 1.3349094
tangentMode: 34
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.26468956
value: 1.4212315
inSlope: 3.3938055
outSlope: 3.3938055
tangentMode: 34
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.3678829
value: 0.99485147
inSlope: -1.9785609
outSlope: -1.9785609
tangentMode: 34
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 0.5813179
value: 1.0321459
inSlope: -0.29753435
outSlope: -0.29753435
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.31828597
- serializedVersion: 3
time: 1
value: 1
inSlope: -0.07677868
outSlope: -0.07677868
tangentMode: 34
weightedMode: 0
inWeight: 0.33333334
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
distortTime: 1
8 changes: 8 additions & 0 deletions Assets/Prefabs/Terrain/Decor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.