/// <summary> /// Plays a sound by creating an empty game object with an AudioSource /// and attaching it to the given transform (so it moves with the transform). Destroys it after it finished playing. /// </summary> /// <param name="clip"></param> /// <param name="emitter"></param> /// <param name="volume"></param> /// <param name="pitch"></param> /// <returns></returns> public AudioSource Play(AudioClip clip, Transform emitter, float volume, float pitch) { audioSpectrumMgrComp.StopSpectrum(); //Create an empty game object GameObject go = new GameObject("AudioContainer"); go.transform.position = emitter.position; go.transform.parent = emitter; audioSpectrumMgrComp.audioContainer = gameObject; //fileMgrComp.audioSourceObj = gameObject.transform; //Create the source AudioSource source = go.AddComponent <AudioSource>(); source.clip = clip; source.loop = true; source.volume = volume; source.pitch = pitch; source.Play(); audioSpectrumMgrComp.StartSpectrum(go.transform); var artistName = (TextMesh)artistNameText.gameObject.GetComponent("TextMesh"); var artistTrack = (TextMesh)artistTrackText.gameObject.GetComponent("TextMesh"); artistName.text = clip.name; //artistTrack.text = clip.name; //Destroy (go, clip.length); return(source); }
void Start() { // Get audio spectrum manager, audio container object, and start the FFT analysis audioSpectrumMgrComp = (AudioSpectrumManager)gameObject.GetComponent("AudioSpectrumManager"); AudioSource newSource = PlayAtIndex(currentSongIndex); audioSpectrumMgrComp.StartSpectrum(newSource.gameObject.transform); fileMgrComp = (FileManager)fileMgrObj.GetComponent("FileManager"); }