Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Ace on August 21, 2014, 02:35:12 PM

Title: UIButton Sound Playing Issue (Can't Create Public Variable)
Post by: Ace on August 21, 2014, 02:35:12 PM
Hello

So I am trying to get sounds working for my buttons.

I put a generic 'playSound("fileName")' in the UIButton onClick method

However I wanted to have an override. So I tried to create a property in UIButton, public string overrideSoundName

But it does not show up in the inspector.

I also do not have the UIButtonSound script (something I saw come up during my research on getting sounds to play).

Can you advise how I can get UIButton display my public string overrideSoundName?

Thanks
Title: Re: UIButton Sound Playing Issue (Can't Create Public Variable)
Post by: ArenMook on August 22, 2014, 03:48:07 AM
Don't modify NGUI's scripts. It will make upgrading difficult. Also override sound makes no sense in a button. A button script doesn't do sounds.

UIPlaySound would be what plays a sound on click etc.

If you need custom functionality that plays sound A or sound B depending on some condition, I strongly advise you creating your own simple script instead, however.
  1. using UnityEngine;
  2.  
  3. public class MyClickSound : MonoBehaviour
  4. {
  5.     public AudioClip clip;
  6.  
  7.     void OnClick ()
  8.     {
  9.         NGUITools.PlaySound(clip);
  10.     }
  11. }
Title: Re: UIButton Sound Playing Issue (Can't Create Public Variable)
Post by: Ace on August 22, 2014, 03:33:01 PM
Ok thanks!