Hi! I have a question to apply a “stop” to this script …
to tighten (“shiftUp” button) I want the audio stops for a while (in this case the value of ShiftTime)
Here I give you the script in c # :
using UnityEngine;
using System.Collections;
public class prueba : MonoBehaviour {
public AudioClip test;
public float testvolumenMax = 1;
public float testpitch = 1;
public float ShiftTime = 0.8f;
AudioSource testSource;
Drivetrain drivetrain;
float volumeFactor;
int i,k;
AudioSource CreateAudioSource(AudioClip clip, bool loop, bool playImmediately, Vector3 position) {
GameObject go = new GameObject("audio");
go.transform.parent = transform;
go.transform.localPosition = position;
go.transform.localRotation = Quaternion.identity;
go.AddComponent(typeof(AudioSource));
go.audio.clip = clip;
go.audio.playOnAwake = false;
if (loop==true){
go.audio.volume = 0;
go.audio.loop = true;
}
else
go.audio.loop = false;
if (playImmediately) go.audio.Play();
return go.audio;
}
void Start () {
drivetrain=GetComponent<Drivetrain>();
testSource = CreateAudioSource(test, true, true,Vector3.zero);
}
void Update () {
if(Input.GetButton ("Throttle")){
if(this.drivetrain.rpm>100){
{if (!testSource.isPlaying) testSource.Play();}
float factor=drivetrain.rpm/drivetrain.maxRPM;
testSource.volume = 0 + testvolumenMax*factor;
testSource.pitch = 0.1f + testpitch*factor +0.3f;
}
}
else
{
float factor=drivetrain.rpm/drivetrain.maxRPM;
testSource.volume = 0.1f + testvolumenMax*factor-0.1f;
testSource.pitch = 0.1f + testpitch*factor -0.15f;
}
}
}
how I can apply a stop time to audio? help me?
Thanks!