- Home /
Question by
amaljoy205 · May 23, 2020 at 05:20 AM ·
audioaudiosourceaudioclipmuteaudio.play
Audiosource.Play() not working
I am having a weird bug. "Audiosource" is not playing the audio. "GetSeletectedAudio()" returns a gameobject with audiosource component. "audiosourceTemp" is assigned correctly. The clip is also correctly loaded,( checked it with "audiosourceTemp.clip.loadState.") but the "audiosource" is not playing. .
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManager : MonoSingleton<AudioManager>
{
public GameObject[] musicobject = new GameObject[10];
private AudioSource audiosourceTemp;
public GameObject GetSelectedAudio()
{
return musicobject[PlayerPrefs.GetInt("SELECTED_AUDIO", 0)];
}
private void PlayingFun()
{
GameObject musicTemp = GetSelectedAudio();
audiosourceTemp = musicTemp.GetComponent<AudioSource>();
audiosourceTemp.Play();
}
}
Is there anything wrong with code? "musicobject" array is populated from inspector. "PlayingFun()" is called externally with mouseclick.
Comment
Your answer
Follow this Question
Related Questions
Play audio at consistent volume 2 Answers
Looping an audio while holding "shift key" 1 Answer
Can an object check on other objects? 1 Answer
AudioSource.clip.time won't work? 2 Answers
Breathing volume increases as player gets more tired 0 Answers