For loop with iTween c#

A picture is worth a thousand words, so I attached one for better understanding my problem. So, for the first option, I figured it out, how to animate boxes in desired order. Here’s the code:

 for (int i = 0; i < rowsMinus; i++)
            {
                print(i);
                for (int j = 0; j < rowsMinus; j++)
                {
                    iTween.MoveTo(box[j], iTween.Hash("z", rows[j].transform.position.z + 80, "time", 0.7, "easetype", "easeInOutQuad", "looptype", iTween.LoopType.none));
                    print(j);
                    if (i == j)
                    {
                        break;
                    }
                }
                yield return new WaitForSeconds(0.7f);
            }

For 2 option, I’m stucked. The question is, how to make an reverse animation with for loop of four boxes in order that I gave you in attached image?

Thank u for your answer!

Kj

You need a way to calculate the positions, and you need to walk your array of boxes in reverse. Here is a bit of example code. Since your is pulled from a larger context, you’ll have to examine this code and then rewrite your code:

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {

	public GameObject[] boxes;
	public float dist = 1.1f; // Distance between pivots unstacked

	void Update() {
		if (Input.GetKeyDown (KeyCode.Space)) {
			StartCoroutine (Unstack());
		}
	}

	IEnumerator Unstack() {
		float posX = boxes[0].transform.position.x + (boxes.Length - 1) * dist;

		for (int i = boxes.Length - 1; i > 0; i--) {
			iTween.MoveTo(boxes*, iTween.Hash("x", posX, "time", 0.7, "easetype", "easeInOutQuad", "looptype", iTween.LoopType.none));*
  •  	yield return new WaitForSeconds(0.7f);*
    
  •  	posX -= dist;*
    
  •  }*
    
  • }*
    }

Hi there. So, I figured it out, how to make it the way I would like to. As you can see in my first option code you just have to do another for loop like this:

 for (int j = boxes.Length; j > 0; j--)
            { 
                for (int i = 1; i <= boxes.Length; i++)
                { 
                    iTween.MoveTo(boxes_, iTween.Hash("z", boxes*.transform.position.z - 80, "time", 0.7, "easetype", "easeInOutQuad", "looptype", iTween.LoopType.none));*_

if (i == j)
{
break;
}
}
yield return new WaitForSeconds(0.7f);
}