I have an audiosource in my scene that will not play any sound. Here is the governing code:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Menu : MonoBehaviour {
public AudioSource menuVoiceover;
public float countdown;
float audioStart = 1f;
private bool timerStarted;
public AVProQuickTimeMovie introMovie;
public Fader fadePlane;
public AudioClip clip;
//void Awake()
//{
// DontDestroyOnLoad(menuVoiceover);
//}
// Use this for initialization
void Start () {
CharacterController playerTrans = GameObject.Find("characterControl").GetComponent<CharacterController>();
playerTrans.mobile = false;
menuVoiceover = GameObject.Find("Plane Audio Source").GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if (timerStarted)
{
countdown -= Time.deltaTime;
audioStart -= Time.deltaTime;
}
if (Input.GetKeyDown(KeyCode.Space) || Input.GetButtonDown("Fire1") && timerStarted == false)
{
//menuVoiceover.Play();
introMovie.Play();
timerStarted = true;
}
if (countdown <= 0)
{
SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1);
GameObject.Find("characterControl").transform.position = (new Vector3(0, 1.169f, .761f));
GameObject.Find("MainCamera").transform.localPosition = (new Vector3(0, .5f, 0));
Destroy(this);
}
if (audioStart <= 0 && !menuVoiceover.isPlaying && timerStarted)
{
menuVoiceover.clip = clip;
menuVoiceover.Play();
}
}
}
I have tried just about everything. The import settings are fine and the clip will play in the editor as intended, but at runtime the audio is not there.
To answer any simple solutions
- I have set the clip in the editor and in code, neither worked.
- I have tried setting the audio source to the root of the hierarchy, still no sound.
- I have ensured that the audiosource settings are set to full 3d (and 2d) spacial blend.
- The volume is set to 1.
- I have set the source priority to 0.
- I have tried setting an output to an audio mixer.
- There is an audio listener in my scene attached to the camera.
- The audio source is enabled.