Author Topic: Set TweenPosition from/to after play  (Read 1862 times)

tnbao91original

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 41
    • View Profile
Set TweenPosition from/to after play
« on: August 20, 2014, 09:39:19 AM »
Hi, can u show me how to set tweenposition from/to again after play ? I use a objectpool and need to reset it but i cant :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Set TweenPosition from/to after play
« Reply #1 on: August 20, 2014, 05:46:07 PM »
GetComponent<TweenPosition>().to = ...?

or

TweenPosition.Begin(...)?

tnbao91original

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 41
    • View Profile
Re: Set TweenPosition from/to after play
« Reply #2 on: August 20, 2014, 10:20:37 PM »
Thank for reply, i solved it but i dont know why this code dont work (OnFinished call UnActive)
  1. void OnEnable()
  2.         {
  3.                 worldCamera = NGUITools.FindCameraForLayer (Target.layer);
  4.                 uiCamera = NGUITools.FindCameraForLayer (gameObject.layer);
  5.  
  6.  
  7.                 pos = worldCamera.WorldToViewportPoint (Target.transform.position);
  8.                 pos = uiCamera.ViewportToWorldPoint (pos);
  9.                 pos.y += 0.20f;
  10.                 pos.z = 0f;
  11.                 transform.position = pos;
  12.  
  13.                 m_TweenLabel = gameObject.GetComponent<TweenPosition> ();
  14.  
  15.                 m_TweenLabel.ResetToBeginning ();
  16.  
  17.                 m_TweenLabel.from = transform.localPosition;
  18.                 m_TweenLabel.to = gameObject.GetComponent<TweenPosition> ().from + Vector3.up * 100;
  19.  
  20.                 m_TweenLabel.PlayForward ();
  21.         }
  22.  
  23.         public  void UnActive()
  24.         {
  25.                 mTarget = null;
  26.  
  27.  
  28.                 gameObject.SetActive (false);
  29.         }

But if i put m_TweenLabel.ResetToBeginning (); in UnActive this work fine

  1. public  void UnActive()
  2.         {
  3.                 mTarget = null;
  4.  
  5.                 m_TweenLabel.ResetToBeginning ();
  6.  
  7.                 gameObject.SetActive (false);
  8.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Set TweenPosition from/to after play
« Reply #3 on: August 22, 2014, 03:08:09 AM »
Ideally, you really should be using TweenPosition.Begin to activate the tween, not change its 'from' and 'to' manually. And for anything more complex than moving from point A to point B, you may also consider creating an animation instead.