-
카테고리
-
세부 분야
게임 프로그래밍
-
해결 여부
미해결
형식 선언관련 질문
21.08.20 23:44 작성 조회수 111
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;
}
}
답변을 작성해보세요.
0
답변 1