Author Topic: PlayReverse after PlayForward , UITweener.Style.Loop doesn't work  (Read 3410 times)

notehaha

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 9
    • View Profile
Hi ArenMook,

I use playForward() for tweening any items, it does fine . But when I trigger playReverse() -after playForward()- it only reverse to 'TO' value without looping.

my workaround is not to use playReverse() it but changing the 'TO' value to minus. This works just OK but cause the tween not smooth.

could you suggest any trick? or I need to override the tween class?

I have tried TweenScale, TweenRotate only

  1.                 if(bTeam)
  2.                 {
  3.                         go_ball.GetComponent<TweenRotation> ().to = new Vector3(0.0f,0.0f,360.0f);
  4.                         go_ball.GetComponent<TweenRotation> ().PlayForward ();
  5.                         //go_ball.GetComponent<TweenRotation> ().style = UITweener.Style.Loop;
  6.  
  7.                 }
  8.                 else
  9.                 {
  10.                         go_ball.GetComponent<TweenRotation> ().style = UITweener.Style.Loop;
  11.                         //go_ball.GetComponent<TweenRotation> ().to = new Vector3(0.0f,0.0f,-360.0f);
  12.                         go_ball.GetComponent<TweenRotation> ().PlayReverse ();
  13.                         go_ball.GetComponent<TweenRotation> ().style = UITweener.Style.Loop;
  14.                 }

you see that i set UITweener.Style.Loop; before and after still doesn't work

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: PlayReverse after PlayForward , UITweener.Style.Loop doesn't work
« Reply #1 on: August 18, 2014, 11:36:06 AM »
If it's looping, then there is no beginning or end. I'm not quite certain what you're trying to do here... if you want it looping, then just setting it to loop is enough. It will play from A to B then back to A. Are you trying to alter the "to" while the loop is active? Why? Can you explain your use case?

notehaha

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: PlayReverse after PlayForward , UITweener.Style.Loop doesn't work
« Reply #2 on: August 19, 2014, 02:36:38 AM »
Hi ArenMook,

Sorry that I give you the info that mislead.

Here are the things:
 - I create a UISprite of a football. the ball is rolling by assigning TweenRotate from Z-axis 0 (From value) to 360 (To value)
Result : the ball rolls forward continuously and smoothly because I set 'loop' in the inspector

 - I want the ball rolls back, so in the source code. I call a method ,PlayReverse() of the ball's gameobject refer to TweenRotate component
Result : the ball rolls backward nicely from the current Z-axis value but it stop rolling when Z-axis is 0 (From value)

Question : how to make the ball rolling backward and loop?


My workaround : since the PlayReverse() only tweens Z-axis from its current value to 0 (From value), I do change the 'To' value from 360 to -360 without calling PlayReverse(). it rolls backward in loop but it's not smooth at the timeI changing the 'To' value.

you can try using Tweens something in loop and call its PlayReversed(). it will stop tween when its current value goes to 'From' value.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: PlayReverse after PlayForward , UITweener.Style.Loop doesn't work
« Reply #3 on: August 19, 2014, 11:16:29 AM »
To be honest for something like this I wouldn't use a tween. I'd write a very simple script to do it.
  1. using UnityEngine;
  2.  
  3. public class BallRotation : MonoBehaviour
  4. {
  5.     public float speed = 360f;
  6.  
  7.     void Update ()
  8.     {
  9.         Vector3 euler = transform.localEulerAngles;
  10.         euler.z += Time.deltaTime * speed;
  11.         transform.localEulerAngles = euler;
  12.     }
  13. }
This way you can easily control the rotation by adjusting the 'speed' value. Make it negative to rotate backwards. Make it 0 to stop. Reduce it gradually to slow down. Much easier than using a tween.

notehaha

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: PlayReverse after PlayForward , UITweener.Style.Loop doesn't work
« Reply #4 on: August 20, 2014, 10:31:46 AM »
Thank you so much, ArenMook. :)

Your support is really much better than IBM buys I coordinate with.  :-X