Author Topic: UIButton Sound Playing Issue (Can't Create Public Variable)  (Read 1755 times)

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
UIButton Sound Playing Issue (Can't Create Public Variable)
« 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton Sound Playing Issue (Can't Create Public Variable)
« Reply #1 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. }

Ace

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 24
    • View Profile
Re: UIButton Sound Playing Issue (Can't Create Public Variable)
« Reply #2 on: August 22, 2014, 03:33:01 PM »
Ok thanks!