한 걸음 두 걸음

unity bgm 배경음 입히기 본문

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로 넣어주면 플레이할 때 자동으로 위의 음악이 재생됩니다.

반응형

'Unity' 카테고리의 다른 글

unity 유니티 mobile CardBoard 적용시키기  (1) 2019.05.26
unity AR Maker 여러 개 활용하기  (0) 2019.05.24
AR rendering  (0) 2019.05.13
unity UI Image 변경  (1) 2019.04.17
VR트래킹  (0) 2019.04.08