Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: dendenny01 on January 09, 2015, 08:56:24 PM

Title: OnHover Triggered when Clicked
Post by: dendenny01 on January 09, 2015, 08:56:24 PM
I have a simple script.To tween  a Button Position and width onHover. The problem that am facing is the script works fine when the mouse is hover on the button but when it is clicked the onHover method is triggered twice. Below is the code that i am ususing. I wanted to know is there any way to detect mouse click.
Original Code without mouse click Detction
  1. public TweenPosition tweenPosition;
  2. public TweenWidth tweenWidth;
  3.  
  4. void OnHover(bool isOver){
  5.       if(isOver){
  6.           tweenPosition.enable=true;
  7.           tweenWidth.enable=true;
  8.           Debug.Log("Event Hover");
  9.       }else{
  10.           tweenPosition.enable=true;
  11.           tweenWidth.enable=true;
  12.           Debug.Log("Event Hover Over");
  13.       }
  14.      
  15. }
  16.  

I want to achieve something like this code below but does not know how can i detect the click event
  1. void OnHover(bool isOver){
  2.       if(isOver && !clicked){
  3.           Debug.Log("Event Hover without click");
  4.       }else if(isOver && clicked){
  5.           Debug.Log("Event Hover with click");
  6.       }else{
  7.           Debug.Log("Event Hover Over");
  8.       }
  9.      
  10. }
  11.  
Title: Re: OnHover Triggered when Clicked
Post by: ArenMook on January 10, 2015, 12:54:59 PM
OnHover is only sent if you are using mouse events, and it's sent before OnClick. If you want the check you're describing, record the pressed state.
  1. bool mUnpress = false;
  2.  
  3. void OnPress (bool pressed) { if (!pressed) mUnpress = true; }
  4.  
  5. void OnHover (bool isOver)
  6. {
  7.     if (isOver && !mUnpress) { ... }
  8.     else if (isOver) { ... }
  9.     else { ... }
  10.     mUnpress = false;
  11. }