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 e-bonneville · Feb 01, 2011 at 03:16 PM · colorlerp

Fading an object with Color.Lerp

The following script isn't working. I copied it directly from the docs, and it's supposed to fade lerpedColor to black; however, it fades it instantaneously. Why?

using UnityEngine; using System.Collections;

public class example : MonoBehaviour { public Color lerpedColor = Color.white; void Update() { lerpedColor = Color.Lerp(Color.white, Color.black, Time.time); } }

I'm not even applying the color yet, just watching it in the Inspector while my game is running. What is going on here?

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 Eric5h5 · Feb 01, 2011 at 07:30 PM 0
Share

Use this for fading objects: http://www.unifycommunity.com/wiki/index.php?title=Fade

1 Reply

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

Answer by Jessy · Feb 01, 2011 at 03:24 PM

The only thing that would make that happen is that you trigger the code after 1 second of game time has elapsed. (Time.time is in seconds and Lerp operates between 0 and 1.)

Just to avoid deductive error, I copied it and pasted it into a new C# script. It did what the docs would have you believe it would do. Make sure that you lerpedColor shows up as white in the Inspector first, though. That code is initiating the color value outside of a function, which means it will fire unpredictably; it's not good practice, but nobody actually wrote that. It was just run through some sort of automatic JS->C# converter.

Comment
Add comment · Show 5 · 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 e-bonneville · Feb 01, 2011 at 03:28 PM 0
Share

Well, I had originally had an if statement in there so I could set a variable in the Inspector to trigger the lerp, but I stripped it out for the sake of simplicity. Same problem with or without if statement.

avatar image e-bonneville · Feb 01, 2011 at 03:32 PM 0
Share

Really? Wow. $$anonymous$$y computer's being funky these days. Yeah, it does start as white, but then when I trigger it, it just jumps to black.

avatar image e-bonneville · Feb 01, 2011 at 03:39 PM 0
Share

Yes, it appears enclosing it in an if statement caused the problem. Can you think of any workarounds? I need to be able to fade objects. Thanks for your time, btw. I appreciate it.

avatar image Jesse Anders · Feb 01, 2011 at 06:00 PM 1
Share

If you've changed your code and are having problems, maybe you could edit your post to include the new code. (Also, the use of Time.time in the Lerp() example in the documentation is misleading at best. At any rate, it's certainly led many new Unity users astray...)

avatar image e-bonneville · Feb 02, 2011 at 07:56 PM 0
Share

Yes, I found that to be the problem, which I've solved now. Thanks, Jessy and Jesse!

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

No one has followed this question yet.

Related Questions

Lerp Color doesn't work 2 Answers

How can I change the color of a light over time? 3 Answers

How do I loop a Color32.Lerp? 3 Answers

How to make two colors lerp independently in this code? 1 Answer

Controlling duration of Color.Lerp in seconds 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