Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: beforethelight on July 18, 2013, 05:21:59 PM

Title: Button 'Sticks' when released
Post by: beforethelight on July 18, 2013, 05:21:59 PM
I have been searching for some help on this for a while but cannot fix it myself or find any information so here is my issue. On some (Android)devices my buttons when pressed then released hang in the pressed position for a second or so after release.  My code is below.  For this example it is a gas pedal for a car and when you release it and it doesn't stop accelerating it becomes a problem quick.  I have run this in FixedUpdate as well as Update with no change.  I have a similar issue with my space lander game buttons sticking.  Any help would be greatly appreciated. Thanks

  1. #pragma strict
  2.  
  3. var release : String;
  4. var go : boolean;
  5. var drive : Drive;
  6.  
  7. function OnPress (isPressed : boolean) {
  8.         if(enabled){
  9.                 go = isPressed;
  10.                 if(!isPressed){
  11.                         OnRelease();
  12.                 }
  13.         }
  14. }
  15.  
  16. function FixedUpdate(){
  17.         if(!go){
  18.                 return;
  19.         }else{
  20.                 drive.Accelerate();
  21.         }
  22. }
  23.  
  24. function OnRelease(){
  25.         drive.Released();
  26. }
  27.  
  28. function OnDisable(){
  29.         if(!go){
  30.                 return;
  31.         }
  32.         go = false;
  33.         drive.Released();
  34. }
  35.  
Title: Re: Button 'Sticks' when released
Post by: ArenMook on July 19, 2013, 01:50:55 AM
NGUI events are sent in LateUpdate, which happens every frame, while physics updates (FixedUpdate) occurs every so often -- by default 20 times per second, although I don't know what it's set to in your Physics settings. Certainly nothing in NGUI would cause the state to "hang" for a second or two.