Hey… is there a way to run playOneShot with audiosource?
This script give me this error: The best overloaded method match for UnityEngine.AudioSource.PlayOneShot(UnityEngine.AudioClip)’ has some invalid arguments`
public AudioSource Audio1;
public AudioSource Audio2;
public AudioSource Audio3;
public AudioSource Audio4;
public AudioSource Audio5;
public AudioSource Audio6;
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.N)) {
Audio1.volume = 0.0f;
Audio2.volume = 0.0f;
Audio3.volume = 0.0f;
Audio4.volume = 0.0f;
Audio5.volume = 0.0f;
Audio6.volume = 0.0f;
}
if (Input.GetKeyDown (KeyCode.A)) {
StartCoroutine (WaitMethod ());
}
else if (Input.GetKeyDown (KeyCode.D)) {
StartCoroutine (WaitMethod2 ());
}
}
IEnumerator WaitMethod(){
yield return new WaitForSeconds(2f);
audio.PlayOneShot(Audio1);
audio.PlayOneShot(Audio2);
audio.PlayOneShot(Audio3);
audio.Play();
}
IEnumerator WaitMethod2(){
yield return new WaitForSeconds(2f);
audio.PlayOneShot(Audio4);
audio.PlayOneShot(Audio5);
audio.PlayOneShot(Audio6);
audio.Play();
}
}
If you want to mute everything … the best thing I can suggest from my own experience is: attaching a script with something like this on to the object with the AudioListener component (usually the main camera)
if (Input.GetKeyDown (KeyCode.Space))
{
this.gameObject.GetComponent<AudioListener>().audio.volume = 0.0f;
}
I just tried this out and it works perfectly fine assuming this is what you need…
Note: If you want to play sound you need to re-set the volume back to 1
Note 2: This will MUTE the sound, not pause it if you need to pause you might need something like this: