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:
function OnPress ()
{
pController.goUp=true;
}
function OnRelease()
{
pController.goUp=false;
}
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:
function OnClick()
{
tweenColor.enabled=true;
tweenScale.enabled=true;
yield WaitForSeconds(0.4);
tweenColor.enabled=false;
tweenScale.enabled=false;
label.color= Color.white;
this.transform.localScale= Vector3(1, 1, 1);
}
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:
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:
var pController : PlayerController;
var isPressedG : boolean =false;
function OnPress (isPressed : boolean)
{
isPressedG = isPressed;
//print (isPressedG);
}
function Update ()
{
pController.goUp= isPressedG;
}
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:
UITweener.Play(bool forward);
I don't suggest enabling/disabling components yourself.