• 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
Question by RudeFX · Nov 17, 2013 at 03:15 AM · materialcolorlerp

Burning Effect Lerp Not werking

Hello, I am trying to make a burning effect, t$$anonymous$$s is my code:

 var lerpedColor : Color = Color.w$$anonymous$$te;
 var Timer = 5.0;
     
 function Update() 
 {
 gameObject.renderer.material.color = lerpedColor = Color.Lerp(Color.w$$anonymous$$te, Color.black, Time.time /Timer);
 }

When placed on a cube for example, it works great lerping down in 5s, but if I then place it on another cube with the game still runnning it is directly black, and not going from W$$anonymous$$te to black.

I realise that it is in memory somewhere but how can I reset it?

Thanks.

Comment

People who like this

0 Show 0
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

Answer by khalladay · Nov 17, 2013 at 05:54 AM

Just keep track of the value of Time.time at the beginning of the lerp on a specific object. The problem you are experiencing is due to the value of Time.time already being beyond the duration of your lerp when you assign it to the second object, storing the start time of the lerp for that object allows you to essentially "reset" the time value for the purposes of your lerp calculation.

 float start = 0.0f;
 
 void StartLerping()
 {
 start = Time.time;
 }
 
 void Update()
 {
 Color lerpedColor = Color.Lerp(Color.w$$anonymous$$te, Color.black, (Time.time - start) / duration); 
 }
Comment

People who like this

0 Show 2 · 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 RudeFX · Nov 17, 2013 at 03:33 PM 0
Share

Thanks for your responce, but I still cant get it to work, its not lerping at all now? Im not too familiar with .cs im still quite new and only use .js. Is the void StartLerping(), a seperate function call, or is that the same as function Start()? As i said no cs knowledge just yet! thanks again!

avatar image khalladay · Nov 17, 2013 at 03:40 PM 0
Share

StartLerping is a separate function call. You need to call that before you start lerping the color in update.

Having it as a separate call allows you to have objects start lerping at times other than the start of the game, it also will allow you to reset the lerp whenever you want. You could also do something like this if you wanted to not have to call StartLerping on objects that start the scene with your lerp script.

 void Update()
 {
 if (start == 0.0f) start = Time.time;
 Color lerpedColor = Color.Lerp(Color.white, Color.black, (Time.time - start) / duration); 
 }
avatar image

Answer by RudeFX · Nov 17, 2013 at 04:37 PM

Thanks a lot everybody, using all of your info I done it like t$$anonymous$$s:

 var lerpedColor : Color = Color.w$$anonymous$$te;
 var duration = 30.0;
 var start = Time.time;
 
 function Update() 
 {
     if (start == 0.0f) 
     start = Time.time;
     gameObject.renderer.material.color = lerpedColor = Color.Lerp(Color.w$$anonymous$$te, Color.black, (Time.time - start ) /duration);
 
 }

Thanks khalladay for pointing out exactly what was going on ;)

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Changing two different objects renderer colour 1 Answer

Material doesn't have a color property '_Color' 4 Answers

How to lerp smoothly between two numbers? 1 Answer

Lerping/Fading between multiple colours 1 Answer

How to make OnTriggerStay ColorLerp start all over again OnTrigger? 2 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