Unity
unity bgm 배경음 입히기
언제나 변함없이
2019. 5. 24. 09:06
반응형
재생하자마자 지정된 음악을 재생시키도록 만들겠습니다.
코드는 아래처럼 굉장히 간단합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class bgm : MonoBehaviour
{
public AudioClip sndExp;
// Start is called before the first frame update
void Start()
{
AudioSource.PlayClipAtPoint(sndExp, transform.position);
}
// Update is called once per frame
void Update()
{
}
}
public AudioClip sndExp;어떤 음원을 재생할 것인지 받아온 후,
start()함수 내에 AudioSource.PlayClipAtPoint(sndExp, transform.position);으로 시작시 플레이하겠다는 것을 해주면 끝.
이제 이를 MainCamera에 적용시켜주고,
가져온 음원을 Snd Exp로 넣어주면 플레이할 때 자동으로 위의 음악이 재생됩니다.
반응형