Author Topic: TweenPosition interrupt  (Read 2460 times)

mansquatch

  • Guest
TweenPosition interrupt
« on: October 10, 2013, 01:08:26 PM »
I have a sprite tween from the top of the screen to the bottom. I am trying to make it so that when you hit the left or right arrow keys during that then the sprite is shift left or right, respectively. I do not want the tween to stop though. Imagine the Tetris tiles. This is the behavior that I am going for. I have tried tweenPosition.begin during the current tween but that only works after the first tween is done. Need help. Thx.

Here is my code:

  1.         // Update is called once per frame.
  2.         void Update () {
  3.                 if(Input.GetKeyDown(KeyCode.RightArrow)){
  4.                         // RIGHT MOVEMENT WILL GO HERE
  5.                 }else if(Input.GetKeyDown(KeyCode.LeftArrow)){
  6.                         // LEFT MOVEMENT WILL GO HERE
  7.                 }
  8.         }
  9.        
  10.         public void Init (Camera cam, int numItems, string[] arr) {
  11.                 isoCamMain = cam;
  12.                 numItemsToSpawn = numItems;
  13.                 arrObjects = arr;
  14.         }
  15.        
  16.         public void SpawnObject() {
  17.                 int rand = Random.Range(1, numItemsToSpawn) - 1; // Offset for zero-based array.
  18.                 // Pull in the object's name (corresponds to the file name in the Resource folder)
  19.                 string s = arrObjects[rand];
  20.                
  21.                 GameObject temp = (GameObject) Resources.Load(s);
  22.                 currSpawnObj = NGUITools.AddChild(isoCamMain.gameObject, temp) as GameObject;
  23.                 currSpawnObj.GetComponent<UISprite>().MakePixelPerfect();
  24.  
  25.                 Vector3 newPos = new Vector3 (0f, 200f, 0.01f);
  26.                 currPosition = newPos;
  27.                 UITweener tp = TweenPosition.Begin(currSpawnObj, 0.1f, newPos);
  28.                 tp.callWhenFinished = "OnSpawned";
  29.                 tp.eventReceiver = this.gameObject;
  30.                
  31.                 TweenAlpha.Begin(currSpawnObj,0.0f,0.0f);
  32.         }
  33.        
  34.         void OnSpawned(){
  35.                 TweenAlpha.Begin(currSpawnObj,0.0f,1.0f);
  36.                
  37.                 Vector3 newPos = new Vector3 (0f, -200f, 0f);
  38.                 UITweener tp = TweenPosition.Begin(currSpawnObj, tweenTimer, newPos);
  39.                 tp.callWhenFinished = "OnComplete";
  40.                 tp.eventReceiver = this.gameObject;
  41.         }
  42.        
  43.         void OnComplete(){
  44.                 Debug.Log("Animation Complete");
  45.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition interrupt
« Reply #1 on: October 11, 2013, 08:31:56 AM »
Consider using 2 objects.

MoveControlledObject
- TweenedObject