Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Starting with Unity having had experience of XNA im not sure if the way i want to solve my problem is the correct way. So id like the opinion of more experienced people.

I am doing a 2.5D game and have no need for 3D sounds that generate from a certain 3D position. I am used to creating a sound manager class that handles the loading of sound assets and has a static public method for each sound effect. This way it works like a toolbox i can call SfxManager.PlayDeathScreamSfx(); from anywhere in the solution.

How could i do the same in Unity?

I have tried making a game object called soundmanager and given it static methods that would play the sound effects but the SoundClips needs to be static for the static methods to be able to use them. And if the SoundClips are static then they dont show up in the inspector and i cant drag'n'drop a sound file on them to reference them.

What to do?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

I am doing a 2.5D game and have no need for 3D sounds that generate from a certain 3D position

Then uncheck the 3D sound checkbox in the sound file inspector.

I have tried making a game object called soundmanager and given it static methods that would play the sound effects but the SoundClips needs to be static for the static methods to be able to use them.

I'd stay away from static stuff. In Unity you usually don't use static managers class. Instead create a SoundManager component, with a AudioSource component attached and expose public methods for playing your sound fx. For example:

[RequireComponent(typeof(AudioSource))]
public class SoundManager : MonoBehavior
{

public AudioClip soundA; //assign clips from inspector
public AudioClip soundB;

public void PlaySoundA()
{
   audio.PlayOneShot(soundA);
}

public void PlaySoundB()
{
   audio.PlayOneShot(soundB);
}
}

From the other behavior, you only need a reference to SoundManager. Assign it to them through inspector or find the GameObject with SoundManager compoents when those behaviors start.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.