Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by MobinYaqoob · Oct 27, 2015 at 07:27 AM · unity 5uiunity 2d

How to make fast a coroutine

   private IEnumerator SwipeLeftPanel(object[] parms)
     {
         //    float right = -PanelRectTransform.offsetMax.x;
         float tempLeft = (float) parms[0];
         float left = PanelRectTransform.offsetMin.x; 
         //    float tempRight = (float)parms[1];
         while (left >= tempLeft)
         {
             left = left - subPeriod;
           PanelRectTransform.offsetMin = new Vector2(left,PanelRectTransform.offsetMin.y);
             Debug.Log("left"+left);
             yield return null;
         }
     }
 

StartCoroutine("SwipeLeftPanel", parms);

I need to move my panel to left side so I give it left and right margin but increment of 1.0f so it slowly move to left and stop when I reaches at certain left and right margin position . left is the amout every time panel move to left.but I want it faster how to do it .thanks in advance :)

Comment
Add comment · Show 1
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 Mike-Geig ♦♦ · Oct 29, 2015 at 02:55 PM 0
Share

Can you just increase the amount you move it each frame?

1 Reply

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

Answer by Dave-Carlile · Oct 29, 2015 at 03:37 PM

yield return null stops the Coroutine until the next frame, which means this is doing one iteration of the loop each frame, which is the same thing you get with Update. So the Coroutine itself is already looping as fast as it can.

So what you need to do is subtract more from left each frame so the panel moves further each frame. A common way to do this sort of thing is to define a speed value that is set to the number of units to move each second. So setting speed to 10...

 float speed = 10.0f;

We would interpret to mean "Move 10 units each second". Now to apply that value we need to scale it by how long it's taking to render a frame using Time.deltaTime. That value is in seconds. By multiplying Time.deltaTime by speed we get the number of units we need to move for an individual frame such that over 1 second we'll have moved 10 units...

 left = left - speed * Time.deltaTime;

So if we're rendering at 60FPS, Time.deltaTime will generally have the value 1/60 or 0.016667. Multiplying that by 10 gives us 0.16667, which is the value we'll subtract from left every frame. If you add that up over 60 frames you'll get to 10. In other words it will take 60 frames to move 10 units, and it will take 1 second to do so.

The nice thing with this setup is that you only really have to be concerned with the value for speed and it's easy to conceptualize "x units per second". So if you want the object to move faster just increase the speed, or if it's too fast then decrease the speed.

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

46 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Text Component Size is not Adjusting 1 Answer

Player character jumping when I wish to only initiate pause - UI Button element. 1 Answer

Slider.value doesn't show the value in real-time but after the execution of the script 1 Answer

UI inputfield not shows mobile keyboard on click 0 Answers

Overlap ScrollRect 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