So here is what I was going for. If you have any idea of how to do this easier, feel free to say anything.
I have a car, and 4 audio clips.
CarFast
CarNormal
CarNormalToFast
CarFastToNormal
So, when the player drives normally, CarNormal would play.
If the player accelerated, the audio clip would change and play CarNormalToFast.
When CarNormalToFast is done playing, it would cross fade into CarFast.
If the car deaccelerates, the audio clip CarFastToNormal would play.
Then, CarNormal would once again, be the audio clip playing.
Soo…this is what I got so far.
var CarNormal : AudioClip;
var CarNormalToFast : AudioClip;
var CarFast : AudioClip;
var CarFastToNormal : AudioClip;
private var Sound : AudioSource = null;
private var CarNormalFlag = 1;
private var CarNormalToFastFlag = 0;
private var CarFastFlag = 0;
private var CarFastToNormalFlag = 0;
function Awake() {
}
function Update () {
if (Input.GetButton ("Up")) {
CarNormalFlag = 0;
CarFastFlag = 1;
}
if (Input.GetButton ("Down")) {
CarFastFlag = 0;
CarNormalFlag = 1;
}
if (CarNormalFlag == 1) {
Sound = gameObject.AddComponent(AudioSource);
Sound.loop = true;
Sound.clip = Normal;
Sound.playOnAwake = true;
NormalFlag = 2;
}
if (CarNormalToFastFlag == 1) {
Sound = gameObject.AddComponent(AudioSource);
Sound.loop = true;
Sound.clip = NormalToFast;
Sound.playOnAwake = true;
}
if (CarFastFlag == 1) {
Sound = gameObject.AddComponent(AudioSource);
Sound.loop = true;
Sound.clip = Fast;
Sound.playOnAwake = true;
FastFlag = 2;
}
if (CarFastToNormalFlag == 1) {
Sound = gameObject.AddComponent(AudioSource);
Sound.loop = true;
Sound.clip = FastToNormal;
Sound.playOnAwake = true;
}
}
But ya, its not working well, stuff gets played infinitely. I basically need a nice way to switch between audio clips.