How do I make chase music for multiple enemies that plays if at least one is chasing the player?

Godot Version

V4.6.1

Question

Hey, so I’m a total rookie and made this account just to ask this question since I can’t find anything online and I’m having trouble figuring it out myself. How would I go about checking multiple enemies for their states and then playing music if at least one is in a chase state? Thank you.

What does “state” mean for you?
We cannot see any of your project or code.

When you have time, please check this post:

You can mark your enemies in a group to find them as a collection later in code.

Though it sounds more like you should have a global/autoload music manager so you can increment and decrement “aggressive” enemies and play specific music when there are more than zero aggressive enemies.

I assume you have a script that toggles enemy ‘chase’ state on/off?

If so:

  1. When an enemy is switched to the ‘chase’ state, make the same script start the music.
  2. Add enemies to an array when they chase the player, or use a variable to count how many are chasing.
  3. When your code makes an enemy stop chasing the player (e.g. it dies, or the player gets too far…), remove the enemy from the array or decrement the variable by 1. If the array is empty or the variable is 0, stop the music.