I'm making a game and I want audio to play when there is at least one instance of an object on-screen. If there isn't, I want to turn it off.
I've tried many things*, but currently I've resorted to making an instance variable 'OnScreen' and then, every tick, I make it so each instance either has 1 or 0, depending on whether they are on-screen. Then, I check whether an instance has 'OnScreen' = 1 and whether the sound isn't playing yet. If that's true, I play the sound.
To turn it off, I look up the nearest instance (to player) and whether it has 'OnScreen' = 0 and then I turn off the sound.
This works, but sometimes the closest instance isn't on screen, while a more further away instance is. There is no sound, even though I want there to be.
I would love it if there would be some way to check whether there is any instance on-screen. Thanks for any help in advance!
*I can't just simply check whether an instance is on-screen, because some are and some aren't. I want the sound to turn on even when not all are on screen, but at least one is.