Author Topic: Is it possible to create a few tweens of the same type via code?  (Read 2207 times)

papatriz

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 10
    • View Profile
Hello,

I am trying to create chaining tweens attached to one gameobject:

TweenPosition -> TweenRotation from 0 to 90 -> TweenRotation from 90 to 180 (I have to separate rotation cause I need to do some things between)

When I did it via inspector all things work nice. But for some reasons it's better for me to create tweens in code.

I've tried it in this way:

  1. var rotate01 = TweenRotation.Begin (transform.gameObject, 0.3f, rotation90);
  2.  
  3. rotate01.delay = 0.99f;
  4. EventDelegate.Add (rotate01.onFinished, ReColor);
  5.  
  6. var rotate02 = TweenRotation.Begin (transform.gameObject, 0.3f, rotation180);
  7.  
  8. rotate02.from = new Vector3 (0, 90, 0);
  9. rotate02.delay = 1.29f;
  10.  

But it creates only one TweenRotation component.

So, is any way to attach more than one copy of tween component and setup them separately, or I have to do it in editor only?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Is it possible to create a few tweens of the same type via code?
« Reply #1 on: May 10, 2016, 06:18:01 PM »
  1. var rotate01 = TweenRotation.Begin (transform.gameObject, 0.3f, rotation90);
  2. rotate01.delay = 0.99f;
  3.  
  4. EventDelegate.Add(rotate01.onFinished, delegate ()
  5. {
  6.     var rotate02 = TweenRotation.Begin(transform.gameObject, 0.3f, rotation180);
  7.     rotate02.delay = 1.29f;
  8. });