Author Topic: Tweening Position back to Starting State  (Read 2727 times)

aikitect

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 27
    • View Profile
Tweening Position back to Starting State
« on: September 20, 2013, 08:20:44 PM »
Hello,

I have the following code that I have attached to the game object that also contains a UIInput component:

  1. public void OnSelect()
  2.         {
  3.                 Vector3 destination = new Vector3(
  4.                         inputContainer.localPosition.x,
  5.                         targetYCoordinate,
  6.                         inputContainer.localPosition.z
  7.                 );
  8.                 TweenPosition.Begin(inputContainer.gameObject, 0.50f, destination);
  9.         }
  10.  
  11.         public void OnClose(string text)
  12.         {
  13.                 Debug.Log(initialPosition);
  14.                 TweenPosition.Begin(inputContainer.gameObject, 0.25f, initialPosition);
  15.         }
  16.  

The OnSelect code works perfectly, and the object tweens to the correct position.  However, the OnClose function does not work, as the object does not move at all (NOTE: I set up the event delegate in OnEnable() which is not shown here and I know it is working because the Debug.Log(initialPosition) shows up in the console).  When I inspect the TweenPosition component, the "to" property and the "duration" property are both unchanged but the "from" property is.

How can I start a tween to initialPosition?

UPDATE: Even when I use the following code, it results in the same behavior.

  1. public void OnClose(string text)
  2. {
  3.         inputContainer.GetComponent<TweenPosition>().Toggle();
  4. }
  5.  

I am using NGUI 2.6.4.
« Last Edit: September 20, 2013, 08:44:00 PM by aikitect »

aikitect

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Tweening Position back to Starting State
« Reply #1 on: September 20, 2013, 08:48:26 PM »
Nevermind, found the solution.  It turns out when you press "Enter", it triggers both OnClose AND OnSelect, and the OnSelect was being called after OnClose, thereby overwriting the Tween.