Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Dreeka on June 18, 2012, 11:14:34 AM

Title: Help with tween and touch
Post by: Dreeka on June 18, 2012, 11:14:34 AM
Hey,

I am experimenting with NGUI, and I have two issues.

First, I am trying to create a virtual button. If the button is held down, the player should move forward, and if the button is released, the player should stop.

I have tried it in the following way:

  1.     function OnPress ()
  2.     {
  3.         pController.goUp = true;
  4.     }
  5.      
  6.     function OnRelease()
  7.     {
  8.         pController.goUp = false;
  9.     }


Secondly, I want my buttons to work in the following way:
When I click on the button, the tween effects should play from start to finish. But instead, if I release th button, the tween effects stops as well. To counter this, I have created a custom script:

  1.     function OnClick()
  2.     {
  3.         tweenColor.enabled = true;
  4.         tweenScale.enabled = true;
  5.        
  6.         yield WaitForSeconds(0.4);
  7.        
  8.         tweenColor.enabled = false;
  9.         tweenScale.enabled = false;
  10.        
  11.         label.color = Color.white;
  12.         this.transform.localScale   = Vector3(1, 1, 1);
  13.     }


But with this script, the tweens start to "break" after a few clicks.

Is there any solutions for my problems?

Thanks!
Title: Re: Help with tween and touch
Post by: ArenMook on June 18, 2012, 11:16:21 AM
There is no "OnRelease". OnPress() function has a boolean flag indicating whether the button was pressed or released, like so:

C# version:
  1. void OnPress (bool isPressed)
Title: Re: Help with tween and touch
Post by: Dreeka on June 18, 2012, 11:36:22 AM
Thanks!

I was able to get it working in the following way:

  1. var pController : PlayerController;
  2. var isPressedG : boolean = false;
  3.  
  4. function OnPress (isPressed : boolean)
  5. {
  6.         isPressedG = isPressed;
  7.         //print (isPressedG);
  8. }
  9.  
  10. function Update ()
  11. {
  12.      pController.goUp = isPressedG;
  13. }

Any thought on the other issue?
Title: Re: Help with tween and touch
Post by: ArenMook on June 18, 2012, 11:52:41 AM
UITweener (base class for all tweens) has a method to play them:
  1. UITweener.Play(bool forward);
I don't suggest enabling/disabling components yourself.