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 mmangual_83 · Jan 07, 2014 at 02:20 PM · c#itweenyieldwaitforseconds

Waiting between pingpong loops

I am using iTween to move an object left to right and vice versa. But I want it to where it reaches its destination, stops for a few seconds and then it continues on its path.

 iTween.MoveTo(_cubeObject, iTween.Hash("name", "Xplane", "position", new Vector3(1, 1, 0), "speed", speed,"easetype", iTween.EaseType.linear, "looptype", iTween.LoopType.pingPong));

I was told by someone in the Unity Community to make this method:

 IEnumerator waitTime(float waitTime)
     {
         yield return new WaitForSeconds(waitTime);
     }


and then simply call it where I want it to stop. But the thing is that I wrote it below the itween line and nothing happens. The object keeps sliding across the world.

Can anyone help me figure this one out? Thanks in advance!

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
2
Best Answer

Answer by GameVortex · Jan 07, 2014 at 03:04 PM

ITween has a callback parameter for when the itween has finished. When the looptype is set to PingPong the callback will be called everytime the target reaches the start and when it reaches the end of the tween. So you can include the callback to a function that pauses the tween, waits and then continues the tween. Here is an example:

 private void Start()
 {
     //Notice the oncomplete at the end. The "oncomplete" references the function it will call, and "oncompletetarget" takes the GameObject it will call the function on (actually SendMessage). 
     iTween.MoveTo(_cubeObject, iTween.Hash("name", "Xplane", "position", new Vector3(1, 1, 0), "speed", speed,"easetype", iTween.EaseType.linear, "looptype", iTween.LoopType.pingPong, "oncomplete", "PauseTween", "oncompletetarget", gameObject));
 }
 
 private void PauseTween()
 {
     StartCoroutine(PauseTween(3));
 }
 
 private IEnumerator PauseTween(float waitTime)
 {
     //Pause all itweens on target object
     iTween.Pause(_cubeObject);
     yield return new WaitForSeconds(waitTime);
     
     iTween.Resume(_cubeObject);
 }

This will start the coroutine when the tween reaches the end, pause the tween for 3 seconds and resume the tween again. Keep in mind that this will stop it when it gets back to the start as well.

Comment
Add comment · Show 1 · 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 mmangual_83 · Jan 07, 2014 at 03:26 PM 0
Share

@GameVortex Yes!!! That worked!!!

avatar image
0

Answer by mischinab · Oct 08, 2018 at 03:03 PM

In the iTween.hash you can use add a parameter "delay", seconds to specify how long to pause between each iteration (e.g. before the ping, and before the pong).

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mysteries of yield 1 Answer

How can I make the health points constantly go down? 1 Answer

Only the first half of my coroutine works 1 Answer

WaitForSeconds not running 2 Answers

WaitForSeconds while having an Update/CoUpdate in C# 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