Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kjurek · Oct 04, 2014 at 05:11 PM · itweenfor loopfor

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

alt text

problem.png (14.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Oct 04, 2014 at 05:49 PM

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[i], iTween.Hash("x", posX, "time", 0.7, "easetype", "easeInOutQuad", "looptype", iTween.LoopType.none));
             yield return new WaitForSeconds(0.7f);
             posX -= dist;
         }
     }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kjurek · Oct 05, 2014 at 07:36 PM 0
Share

hi. It's not working as it should. It moves boxes but not the way I would like. Something is missing. Your code moves boxes all in one sequence. I would like to move boxes in four sequences. In the first sequence move all of them. In the second the last one stays and the others move. In next step, we move only two boxes, in next one last one. like I showed on attached image on option 2. Am I clear?

avatar image Kjurek · Oct 06, 2014 at 07:47 AM 0
Share

I marked your answer, because my attached image was a little bit disturbing. And your code does what I was asking for. The thing is I didn't asked right! In comment above I tried to explain what is the real animation scenario.

avatar image robertbu · Oct 06, 2014 at 01:28 PM 0
Share

I'm sorry I was unable to give you what you wanted. Your comment is still a bit confusing since it appears that the object are moving to the left (based on your comment) but your arrows are pointing to the right?

avatar image
0

Answer by Kjurek · Oct 06, 2014 at 08:18 AM

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[i], iTween.Hash("z", boxes[i].transform.position.z - 80, "time", 0.7, "easetype", "easeInOutQuad", "looptype", iTween.LoopType.none));
 
                     if (i == j)
                     {
                         break;
                     } 
                 }
                 yield return new WaitForSeconds(0.7f);
             }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Issues with Inventory script 0 Answers

Cloud recognition in Vuforia 0 Answers

Shorten code with FOR loop 1 Answer

Itween CRSpline to BezQuad 2 Answers

Android multitouch problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges