70 lines
1.5 KiB
C#
Raw Normal View History

using System;
using Unity.VisualScripting;
using UnityEngine;
public class TempMusicChange : MonoBehaviour
{
public AudioClip changeClipTo;
private AudioSource audioSource;
private AudioClip originalClip;
private AudioReverbFilter rev;
private AudioLowPassFilter lpf;
// Start is called before the first frame update
void Start()
{
GameObject audioController = GameObject.Find("AudioController");
audioSource = audioController.GetComponent<AudioSource>();
rev = audioController.GetComponent<AudioReverbFilter>();
lpf = audioController.GetComponent<AudioLowPassFilter>();
originalClip = audioSource.clip;
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.tag.Equals("Player"))
return;
audioSource.clip = changeClipTo;
audioSource.Play();
checkFilters(true);
}
private void OnTriggerExit2D(Collider2D other)
{
if (!other.tag.Equals("Player"))
return;
audioSource.clip = originalClip;
audioSource.Play();
checkFilters(false);
}
void checkFilters(bool enter)
{
if (enter)
{
rev.enabled = false;
lpf.enabled = false;
}
else
{
rev.enabled = true;
lpf.enabled = true;
}
}
}