So I'm creating a game in unity and I want the music to change when the player picks up different items eg a coin, bread, etc. But I'm not sure where I would get started with that does anyone have links or knowledge on how I can do this? Also I am using FMOD but don't want to use FMOD to do this
Unity audio perameters when picked up item?
35 Views Asked by myzeze At
2
There are 2 best solutions below
0
On
Attach a script containing this to the AudioSource that plays the music.
Make sure that loop is unchecked on the AudioSource
public AudioClip normalClip;//the music to play normally
public AudioClip specialClip;//the music to play when an item is obtained
AudioSource audioSource;//the music player
void Start()
{
audioSource = GetComponent<AudioSource>();//find the music player on this GameObject
}
void Update()
{
//if music player finished playing, start next loop of normal music
if (!audioSource.isPlaying)
{
audioSource.clip = normalClip;
audioSource.Play();
}
}
//starts a loop of the item-obtained music
void OnObtainedItem(){
audioSource.clip = specialClip;
audioSource.Play();
}
When you collect an item, call OnObtainedItem();
Maybe you can use the component, called Box Collider.
How to open API
Search and find
OnTriggerEnter