I have this proble, i want that when the game object tagged "Boss" spawns, the music changes, but when the boss is killed the music go back to normal. i´ve tried lot of things, i need help. I use a game object to controll the music, and 2 Audio sources.
this is my code:
public AudioSource _AudioSource1;
public AudioSource _AudioSource2;
GameObject boss;
bool bossAlive = false;
bool bossDeath = false;
void Start()
{
boss = GameObject.FindGameObjectWithTag("Boss");
_AudioSource1.Play();
}
void Update()
{
if(boss)
{
bossAlive = true;
bossDeath = false;
}
if (!boss)
{
bossAlive = false;
bossDeath = true;
}
if (bossAlive)
{
if (_AudioSource1.isPlaying)
{
_AudioSource1.Stop();
_AudioSource2.Play();
}
bossAlive = false;
}
if (bossDeath)
{
if (_AudioSource2.isPlaying)
{
_AudioSource2.Stop();
_AudioSource1.Play();
}
bossDeath = false;
}
}
↧