Support => NGUI 3 Support => Topic started by: Doddler on May 08, 2013, 02:39:53 AM
Title: UIButton Sound OnClick and OnMouseOver events
Post by: Doddler on May 08, 2013, 02:39:53 AM
I'm sorry if this is explained elsewhere, what I'm doing is I have two UIButton Sound scripts on a single UIImage Button object, one for OnClick and one for OnMouseOver. The problem is that when you click, the OnMouseOver event is also triggered at the same time (even though the button never loses focus). The best I can tell, I couldn't find an easy way to have it only play a click sound when clicked. Is there anything I'm doing wrong here?
Title: Re: UIButton Sound OnClick and OnMouseOver events
Post by: ArenMook on May 08, 2013, 06:24:59 PM
OnMouseOver is a Unity event. NGUI uses OnHover.
Title: Re: UIButton Sound OnClick and OnMouseOver events
Post by: Doddler on May 08, 2013, 10:03:20 PM
When run, the program generates the following output:
(http://puu.sh/2PHe7/44811cc125.png)
The first OnHover event is triggered when the mouse moves over the button. Then OnPress is triggered when the mousebutton is pressed down. When the mouse button is released, OnPress is triggered with isPressed now false, OnHover gets called a second time (I think this is the bug), followed by OnClick. Then lastly OnHover is false when the object loses focus.
Knowing how it works I guess it's pretty simple to make a work around, but I think it's still technically a bug?
Title: Re: UIButton Sound OnClick and OnMouseOver events
Post by: ArenMook on May 09, 2013, 07:19:05 AM
The way it is right now is so that states are reverted correctly with minimal work on the user's part. Pressed state overwrites hover state, and when it's released, hover state returns.
Title: Re: UIButton Sound OnClick and OnMouseOver events
Post by: Doddler on May 09, 2013, 12:56:25 PM
The way it is right now is so that states are reverted correctly with minimal work on the user's part. Pressed state overwrites hover state, and when it's released, hover state returns.
Alright, that makes sense, thanks for the help. In the mean-time, I've modified the OnHover method in NGUI's UIButtonSound class as follows to prevent the OnHover sound from playing when a click is performed.