Created
January 31, 2019 16:00
-
-
Save melsov/9f3c9b1819dae6ee0650760fc05657be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
[System.Serializable] | |
public struct MinMaxF | |
{ | |
public float min, max, _curr; | |
public float curr { | |
get { | |
return Mathf.Clamp(min, max, _curr); | |
} | |
set{ | |
_curr = value; | |
} | |
} | |
} | |
public class NoiseMaker : MonoBehaviour | |
{ | |
public struct AccelInfo | |
{ | |
public bool isPedalToMetal; | |
} | |
[System.Serializable] | |
public struct AudMinMax | |
{ | |
public MinMaxF pitch; | |
} | |
[SerializeField] | |
public AudMinMax minMax; | |
public AudioSource accelAud; | |
public void updateAccelSound(AccelInfo ai) | |
{ | |
if(ai.isPedalToMetal) | |
{ | |
print("is metal"); | |
minMax.pitch._curr += .02f; | |
if(!accelAud.isPlaying) | |
{ | |
accelAud.Play(); | |
} | |
} | |
else | |
{ | |
minMax.pitch._curr -= .05f; | |
if(minMax.pitch.curr == minMax.pitch.min) { | |
//accelAud.Stop(); | |
} | |
} | |
print(minMax.pitch._curr); | |
float mm = Mathf.Clamp(minMax.pitch._curr, -2f, 10f); | |
accelAud.pitch = mm; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment