Here is the script that we have so far:
using UnityEngine;
using System.Collections;
public class PitchChange : MonoBehaviour
{
public AudioSource Audio;
public float StartingPitch = 1.0f;
public float EndingPitch = 2.0f;
public int PitchScaleFactor = 3;
bool isMousePressed = false;
void OnMouseDown()
{
isMousePressed=true;
}
void OnMouseUp()
{
isMousePressed=false;
}
// Update is called once per frame
void Update ()
{
//If mouse is pressed, increase pitch
if(isMousePressed == true)
{
if(Audio.pitch <= StartingPitch)
{
Audio.Play();
}
//Only increase pitch if "EndingPitch" value has not been reached
if(Audio.pitch <= EndingPitch)
{
Audio.pitch += ((Time.deltaTime * StartingPitch) / PitchScaleFactor);
}
}
//Otherwise, decrease pitch back to normal, until we reach starting pitch
else
{
if(Audio.pitch > StartingPitch)
{
Audio.pitch -= ((Time.deltaTime * StartingPitch) / PitchScaleFactor);
}
else
{
Audio.Stop();
}
}
Debug.Log(Audio.pitch);
}
}
Basically looking to have the wind up of the audio be a certain length and then the wind down last longer/shorter than the wind up vice versa. Here is the project so far. link text
Any help is appreciated!