Author Topic: [solved]Problem with UISoundVolume  (Read 7097 times)

stilghar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
[solved]Problem with UISoundVolume
« on: April 10, 2013, 03:56:52 PM »
Hi!

I recently bought NGUI, having lots of fun with it! Great tool. Now the question of a newbie in trouble:

I have attached the following simple script to my main camera (not the UI camera):

http://hastebin.com/coyiloxugu.py

And then I put a UISoundVolume script on an NGUI slider. But the volume of the song played doesn't seem to be affected. What may be wrong? I tried adding a Debug.Log inside the OnSliderChange of the UISoundVolume to see if this was called at all and it seems to be the case. So, I don't understand then what could be the problem.

Any help?

Stilghar
« Last Edit: April 13, 2013, 07:47:31 PM by Nicki »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem with UISoundVolume
« Reply #1 on: April 10, 2013, 03:58:31 PM »
Adjusting the slider will not affect the volume of the sounds that are currently playing. Only sounds that you will play after the adjustment.

stilghar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Problem with UISoundVolume
« Reply #2 on: April 10, 2013, 04:01:59 PM »
Ok, then it seems I can't use UISoundVolume for what I wanted.

I have created a menu where I have two sliders one for music and one for effects. I wanted these to affect all the music and sounds in my game. Any tip on how to achieve this? What is the point then of having NGUITools.soundVolume in the first place then? I don't get it...

Stilghar

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem with UISoundVolume
« Reply #3 on: April 10, 2013, 08:50:03 PM »
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(UISlider))]
  4. public class UIVolumeSlider : MonoBehaviour
  5. {
  6.         public AudioSource audioSource;
  7.  
  8.         void Awake ()
  9.         {
  10.                 UISlider slider = GetComponent<UISlider>();
  11.                 slider.sliderValue = audioSource.volume;
  12.                 slider.eventReceiver = gameObject;
  13.         }
  14.  
  15.         void OnSliderChange (float val)
  16.         {
  17.                 audioSource.volume = val;
  18.         }
  19. }

stilghar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Problem with UISoundVolume
« Reply #4 on: April 11, 2013, 02:27:50 PM »
Thanks for the tip! This helps!

...still I don't understand the purpose of NGUITools.SoundVolume though... What is the use case for it then?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem with UISoundVolume
« Reply #5 on: April 11, 2013, 08:43:54 PM »
All NGUI sounds are played taking that volume value into consideration. UI sounds are generally short, so it doesn't matter if it alters the actively playing sounds or not.

In your case you are altering the volume of something that's actively playing -- music. You need to both play it and approach it differently, thus the script above.

stilghar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Problem with UISoundVolume
« Reply #6 on: April 13, 2013, 03:16:55 PM »
Many thanks Aren! It makes sense.