Quantcast
Channel: Questions in topic: "tagging"
Viewing all articles
Browse latest Browse all 120

Change music when enemy is in scene

$
0
0
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; } }

Viewing all articles
Browse latest Browse all 120

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>