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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Rick74 · Oct 07, 2013 at 06:14 PM · javascriptmathf.lerp

How would you start another lerp based off of a condition of a current lerp?

I'm trying to monitor the state of a current lerp, and then start another lerp mid lerp of the first lerp!

:P

(sorry just like typing lerp!)

But seriously, If I have a Mathf.Lerp making a number go from 1-0, I'm trying to start another lerp when that number reaches say the mid point (.5). But for some reason, I'm not getting the results I'm after.

Here's my code;

 if ( lives == 0 )
     {
         var t:         float = 0.0f;
         var on:     float = 1.0f;
         var off:    float = 0.0f;
         
         while(t < 1)
            {
             t += Time.deltaTime / panelFadeOutTime;
             panel.GetComponent(UIPanel).alpha = Mathf.Lerp (on, off, t);
             yield;
             
         }
         
      }
      if (panel.GetComponent(UIPanel).alpha <= .8)
     {
           var r:        float = 0.0f;
                         
            while(r < 1)
         {
               r += Time.deltaTime / panelFadeOutTime;
                panelLose.GetComponent(UIPanel).alpha = Mathf.Lerp (off, on, r);
                yield;
            }
     }

These lerps are controlling an alpha attribute of two different sprites, I'm simply trying to fade one down and fade one up just before the first one fades down.

What's happening with this current code is one will fade down completely, and then one fades up.

thanks for reading!

Comment
Add comment · Show 2
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 meat5000 ♦ · Oct 07, 2013 at 06:24 PM 0
Share

$$anonymous$$aybe declare r next to t at the start of the script. Don't forget to reset them if you need to.

I'm assu$$anonymous$$g this is inside Update()? Lerp needs to be called constantly to update the value. If this runs through once you won't get the effect you are trying to achieve.

avatar image Rick74 · Oct 07, 2013 at 06:26 PM 0
Share

It's inside a function which is inside of Update (). Everything is lerping fine, it's just one lerp finishes before another lerp starts.

Could you type out what you mean by declare r next to t? I'm still new and learning. And code examples of the right way help me learn this easier.

1 Reply

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

Answer by meat5000 · Oct 07, 2013 at 07:22 PM

I would declare t and r at the start of the script and set them to 0. Increment the timers, then zero them when you want to reset the lerps.

Your Lerps are inside while loops which is why one finishes before the other. A while loop will complete until the condition is false before continuing with the rest of the script. Remove the whiles and use an if to add running conditions instead.

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 Rick74 · Oct 07, 2013 at 08:25 PM 0
Share

I'm sure what you are saying is right, however if you could just give me an example in code, so I don't get it wrong...that would be great.

Like I had already said, I'm new to coding and learn best by seeing what the right way is rather then someone trying to talk me through it.

It's like asking for directions, I'd understand better with a map drawn then someone trying to explain it verbally.

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

16 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

Related Questions

Sliding Door OnButtonDown 4 Answers

how to use time on lerp 2 Answers

Keeping track of how many times games as been Restarted 0 Answers

Trying to display object name of raycast hit 1 Answer

Continuing movement after animaton on GetButtonUp 0 Answers


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