Hello guys, I'm very new to Unity, been doing the Scavengers tutorial (2D Roguelike) from the learning section. I've reached the 13 out of 14 video, just adding the sound I'm doing exactly as they do it in there, but it does not work. I've been typing the exact same code, and did the exact same SoundManager game object, and it just doesn't work. I'm currently half way of the video tutorial to add the sound, but the background music should be on by now. here is the code of my SoundManager Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class SoundManager : MonoBehaviour { public AudioSource efxSource; public AudioSource musicSource; public static SoundManager instance = null; public float lowPitchRange = .95f; public float highPitchRange = 1.05f; void Awake () { if (instance = null) instance = this; else if (instance != this) Destroy(gameObject); DontDestroyOnLoad(gameObject); } public void PlaySingle(AudioClip clip) { efxSource.clip = clip; efxSource.Play(); } public void RandomizeSfx(params AudioClip [] clips) { int randomIndex = Random.Range(0, clips.Length); float randomPitch = Random.Range(lowPitchRange, highPitchRange); efxSource.pitch = randomPitch; efxSource.clip = clips[randomIndex]; efxSource.Play(); } } and a screen shot
Don't have that. I'm at the same stage as the tutorial, and when he launch the game, the sound works. the SoundManager is the only new thing that I added but if in the tutorial video it works for him, then it should work for me too.
I've put the Audio Source in the SoundManager, and checked the "Loop" same as he did. here is the tutorial video, im at 6:13, this is where he launches the game, and the background music works
What you have so far should work.. you've got your sound manager in the scene.. your sound manager has an audio source on it with a clip attached... it's set to play on awake. Weird. Open up the audio right in Unity and play it. You can click on the audio file in Unity's project explorer, and there should be a play button or something in the preview. Make sure you're hearing sounds. Maybe your PC's sound isn't working right..??
I did open the audio file, and it does work. But in game, nothing. This makes me frustrated, I don't want to keep going until I got it all working
Does your Camera have an AudioListener component attached to it? Did you somehow end up with multiple SoundManager script instances in the scene?
How can I check if I have multiple SoundManager script instances? And yes, my Camera does have AudioListener component attached
Since you are on windows, you should have a sound icon in your system tray (I see it in your screenshot, so it's there). When you play the game, click on that icon and see if sound is playing there. If you don't see anything there, check the mixer to make sure the volume on the Unity player isn't muted/turned down.
No, it is, I see it on in the one screenshot now. Well, you could zip up your project and provide it here. Other thing to try is to try to play the audio through the script to see if that even works. I also thought it could be your sound was set up as 3d, but if you're following the tutorial, I don't think that would be it.
Code (CSharp): if(instance = null) you have the above in your code but it should read Code (CSharp): if (instance == null) a double == means is it equal, not it equals, might help along the way It looks to me that your instance of the soundmanager class is never being set, so it just keeps getting nullified.
Good catch! Surprised how many of us looked at this and didn't notice that. And fixing that will fix your sound playing issue.
Omg thank you so much! And a really good catch, thank you again! The sound works! Now I can continue And if we're all already here, any tips for a Unity rookie ? would like articles and such to read, tutorials won't be enough to learn I guess
Honestly. Practice. Tutorials really are great. Unity has a lot of good examples and youtube has several good examples done by various people. A lot of times they might even mention tips and tricks to help out. Unity also publishes blog post and articles over different things every now and then. Also, many times if you just Google for something you can usually find other blogs and articles about the feature and how it may have been handled. Don't give up either! Even when you run into an error. Debugging is a part of programming, even if it does seem frustrating at times.