Skip to content

Instantly share code, notes, and snippets.

@melsov
Created January 31, 2019 16:00
Show Gist options
  • Save melsov/9f3c9b1819dae6ee0650760fc05657be to your computer and use it in GitHub Desktop.
Save melsov/9f3c9b1819dae6ee0650760fc05657be to your computer and use it in GitHub Desktop.
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