Can an object check on other objects?

I want to create an “Audio Controller” game object that holds all of the sound clips for my game. However in order for that to work that object would need to be able to get information about all the other objects in the game that i want to associate sounds with.

For example, if my player ship comes into contact with an enemy bullet I want the ship and the bullet to call Destroy() while the Audio Controller calls explosion.Play().

By what method would I be able to pass information to the Audio Controller that this event has taken place?

Thanks for any advice!

You can use an Event system that you can research in Unity’s Documentation.

You could store a reference to every gameObject that needs to make a sound in the AudiController.

Or You could store a reference to the AudioController in every game object that makes a sound. I think I would do this option, but I’m not knowledgeable in Unity’s audio classes.

So in the game obejct that needs to make a sound add

public AudioController myAudioController;

and when the sound is meant to be played call:


And drag the AudioController object onto the field for its reference in each object which will use it. That is done in the inspector for any object containing a script which declares a public reference for AudioController.