Author Topic: [SOLVED] Can't hear NGUITools.PlaySound()  (Read 3960 times)

tydygunn

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
[SOLVED] Can't hear NGUITools.PlaySound()
« on: October 03, 2013, 07:06:25 PM »
Hi all. I'm working out of NGUI version 2.7.0 (waiting until the next new project before we make the jump to 3.0) and I'm having a bit of trouble with NGUITools.PlaySound(). I can't hear the sound.

- I logged out the code. It is executing that line and the audio clip is not null.
- NGUITools.soundVolume is logging out to be 1.
- I have a camera in the scene with an Audio Listener. It is active.
- The sound I want to play is 2D, and it's the standard NGUI "Tap" sound at this point, though that will change later.
- I can play and hear sounds that I assign to an AudioSource, so I know that my scene can play audio.

Not really sure what could be going on. I think I've covered all my "derp" bases here, but please correct me if I'm missing something obvious. My code is simply:

  1. public AudioClip tapSound; // Confirmed set in editor
  2.  
  3. void OnClick(){
  4.         Debug.LogWarning(NGUITools.soundVolume); // This does log out, so I know the code is executing.
  5.         NGUITools.PlaySound(tapSound, 1);
  6. }
  7.  

Thanks a bunch!

EDIT: I said 2.2.7 the first time I posted this. I meant 2.7.0.
« Last Edit: October 04, 2013, 09:51:12 AM by tydygunn »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Can't hear NGUITools.PlaySound()
« Reply #1 on: October 04, 2013, 02:09:10 AM »
PlaySounds plays on your main camera as a 2D sound. I suggest debugging to determine which camera it's choosing for you. Maybe you have more than one camera marked as "main camera".

P.S. Although looking at the code, PlaySound does a search first for an AudioListener. Maybe it's finding the wrong one in your case.

tydygunn

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Can't hear NGUITools.PlaySound()
« Reply #2 on: October 04, 2013, 09:50:50 AM »
Fixed! I had two cameras marked "MainCamera" and only one of them had an AudioListener attached to it. My guess is that NGUI was pulling Camera.mainCamera, and Unity kept returning the camera without an AudioListener on it. It does strike me as odd that would happen though, since NGUI looks for an AudioListener first and there's only 1 AudioListener existing in my scene (and that object is active).

But whatever, the problem is solved! I changed the secondary camera to "Untagged" and now I can hear sound again. Thanks!