유니티에서 Silder를 이용해서 오디오 볼륨을 조절하는 기능을 구현해 보았다.
우선 GameObject를 만들어 AudioManager라고 이름을 지어주고 AudioManger.cs 스크립트를 만들어 붙여준다.
AudioManager.cs 스크립트를 열어 코드를 작성해준다.
using UnityEngine;
using UnityEngine.UI;
public class AudioManager : MonoBehaviour
{
public AudioSource bgmSource;
public Slider bgmVolumeSlider;
public AudioClip clip;
private void Awake()
{
bgmSource = GetComponent<AudioSource>();
}
void Start()
{
bgmVolumeSlider.value = bgmSource.volume;
bgmSource.clip = this.clip;
bgmSource.loop = true;
bgmSource.Play();
}
void Update()
{
bgmSource.volume = bgmVolumeSlider.value;
}
}
코드 작성을 완료했으면 슬라이더 UI를 추가해 적당한 크기로 설정후
AudioManager에 Audio Source 컴포넌트, bgm clip, 슬라이더 UI를 붙여준다
이제 시작버튼을 눌러 잘 작동하는지 확인을 해주면 완성
'내일배움캠프 > TIL' 카테고리의 다른 글
TEXT RPG 만들기2 (인벤토리 만들기, 장착 관리) (0) | 2025.02.04 |
---|---|
TEXT RPG 만들기(기본 틀 다지기, 상태창 만들기) (0) | 2025.02.03 |
2025-01-22 List<T>, Array, Dictionary(Tkey, TValue) 비교 (0) | 2025.01.22 |
2025-01-21 Dictionary(딕셔너리) (0) | 2025.01.21 |
2025-01-20 GitHub 사용일지 (0) | 2025.01.20 |