Boss Health and Music
No Boss Music, No Boss fight
Today we will be doing two things: giving the boss a health system and starting boss fight background music at the right time.
We put an Audio Source component on our Boss with a boss stage music. When the boss is defeated the music will stop as well.
In the inspector note that ‘Play On Awake’ is turned off.
In our script we will use AudioSource.PlayDelayed to start playing the music.
Suggest a change Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all…
Boss Health Script
A simple script that starts playing the boss music with delay in Start().
Boss health can only be damaged by objects with tag Laser and the player ramming the boss will only damage the player.
Last but not least we need an explosion on the death of our boss.
[SerializeField] GameObject _explosionPrefab;
private int _bossHealth = 10;
private AudioSource _audioSource;
private float _delay = 7f;
_audioSource = GetComponent<AudioSource>();
private void OnTriggerEnter2D(Collider2D other)
if (other.tag == "Player")
else if (other.tag == "Laser")
if (_bossHealth <= 0)
private void BossDeath()
Instantiate(_explosionPrefab, transform.position, Quaternion.identity);