인프런 커뮤니티 질문&답변
형식 선언관련 질문
작성
·
193
0
12:31 코드 기준
AudioSource는 컴포넌트니까 GameObject에 붙어서 사용해야 한다는 뜻이고,
go.AddComponent<AudioSource>()는 go에 AudioSource 컴포넌트를 붙이고 반환하는 거니까 그냥 _audioSource[]를 AudioSource 형식으로 선언한 건가요?
이해한걸 바탕으로 GameObject 형식으로 선언해봤는데 맞는지 한번 체크 부탁드려도 될까요?
GameObject[] _audioSource = new GameObject[(int)Define.Sound.MaxCount];
// MP3 Player -> AudioSource
// MP3 음원 -> AudioClip
// 관객(귀) -> AudioListener
public void Init()
{
GameObject root= GameObject.Find("@Sound");
if (root == null)
{
root = new GameObject { name = "@Sound" };
Object.DontDestroyOnLoad(root);
string[] soundNames = System.Enum.GetNames(typeof(Define.Sound));
for(int i = 0; i < soundNames.Length - 1; i++)
{
GameObject go= new GameObject { name = soundNames[i] };
_audioSource[i] = go.AddComponent<AudioSource>().gameObject;
go.transform.parent=root.transform;
}
_audioSource[(int)Define.Sound.BGM].GetComponent<AudioSource>().loop=true;
}
}
퀴즈
72%나 틀려요. 한번 도전해보세요!
Unity에서 사운드를 재생하기 위해 기본적인 세 가지 구성 요소는 무엇일까요?
Audio Mixer, Audio Effect, Audio Group
Audio Source, Audio Clip, Audio Listener
Sound Manager, Sound Effect, Background Music
Audio Input, Audio Output, Audio Processor





