: 전체 볼륨과 배경음, 효과음을 각각 따로 조절하기 위해 Audio Mixer 사용
public class AudioMixerController : MonoBehaviour { [SerializeField] private AudioMixer m_AudioMixer; [SerializeField] private Slider m_MusicMasterSlider; [SerializeField] private Slider m_MusicBGMSlider; [SerializeField] private Slider m_MusicSFXSlider; private void Awake() { m_MusicMasterSlider.onValueChanged.AddListener(SetMasterVolume); m_MusicBGMSlider.onValueChanged.AddListener(SetMusicVolume); m_MusicSFXSlider.onValueChanged.AddListener(SetSFXVolume); } public void SetMasterVolume(float volume) { m_AudioMixer.SetFloat("Master", Mathf.Log10(volume) * 20); } public void SetMusicVolume(float volume) { m_AudioMixer.SetFloat("BGM", Mathf.Log10(volume) * 20); } public void SetSFXVolume(float volume) { m_AudioMixer.SetFloat("SFX", Mathf.Log10(volume) * 20); } }
public class SceneChanger : MonoBehaviour { //public SceneAsset scene; public void StartButton() { //if (scene != null) //{ SceneManager.LoadScene("stage1"); //} } public void LoadGame() { string savedStage = PlayerPrefs.GetString("SavedStage", "Stage1"); SceneManager.LoadScene(savedStage); } public void GoToTitle() { SaveGame(); SceneManager.LoadScene("TitleScene"); } private void SaveGame() { string currentScene = SceneManager.GetActiveScene().name; PlayerPrefs.SetString("SavedStage", currentScene); PlayerPrefs.Save(); } public void NextStage() { string currentScene = SceneManager.GetActiveScene().name; string nextScene = ""; if (currentScene == "Stage1") nextScene = "Stage2"; else if (currentScene == "Stage2") nextScene = "Stage3"; else if (currentScene == "Stage3") nextScene = "TitleScene"; SceneManager.LoadScene(nextScene); } public void Exit() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } }
public float damagePerSecond = 5f; private bool isDamaging = false; private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player") && !isDamaging) { StartCoroutine(ApplyDamage(other)); } } private void OnTriggerExit(Collider other) { if (other.CompareTag("Player")) { StopAllCoroutines(); isDamaging = false; } } private IEnumerator ApplyDamage(Collider player) { isDamaging = true; while (isDamaging) { PlayerInfo playerInfo = player.GetComponent<PlayerInfo>(); // PlayerInfo 스크립트가 있다고 가정 if (playerInfo != null) { playerInfo.health -= damagePerSecond; Debug.Log("Player damaged! Current health: " + playerInfo.health); } yield return new WaitForSeconds(1f); // 1초 간격으로 데미지 적용 } }