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 /
avatar image
0
Question by Wolfrik_Creations · Jun 02, 2016 at 07:23 AM · javascriptfunctionfademethodfading

Fade Float Function

How can I make a float fade using a function? Using it like FadeSomeFloat(myFloat, 0.0, 10.0, 30); and that would fade the variable "myFloat" from 0 to 10 in 30 seconds.

Most would be thinking "why not lerp?" but A: lerping is annoying as hell. and B: I need to run this in another function so that my fades to rain rather than just jumping to it, this means that I'm gonna need to fade like 6 different variables.

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 allenallenallen · Jun 02, 2016 at 08:26 AM 0
Share

Do you want to call it only once or once every update?

2 Replies

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

Answer by Alec-Slayden · Jun 02, 2016 at 08:24 AM

As a technical answer to your question, you'll need to use either a coroutine or a manually called method that moves the value over time, but as far as I know there is no out-of-the-box single-call method, only interpolation utilities you will have to continuously call.

Essentially, you'll need to interpolate, however if you don't like Lerp, there is also SmoothDamp MoveTowards and for other use cases, InverseLerp

you could always write your own static utility class to implement a coroutine on the fly from a single call, but at that point you are starting to create the basis of a tween engine, a utility specifically designed to help animate or adjust values between two states.

Now, for the less technical answer to your question, there are several of these tweening engines freely available on the asset store, as well as some fine paid ones, that are simple and powerful, and can make your life much easier for fading colors, positions, and floats with a one-time method call, and it sounds like this might be a good solution for you. I do have my favorites, but rather than plug them I encourage you to take a look and see which solution will suit you best

Comment
Add comment · Show 4 · 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 Wolfrik_Creations · Jun 02, 2016 at 06:52 PM 0
Share

Wow! This is probably the best answer I've gotten so far! (on the whole site)

This should work, I will give these a try and reply back in an hour or two and if it works then I will accept the answer.

Thank you very much! I tried to google a bunch of stuff but when I google anything it comes up with completely unrelated stuff for some reason, it just seems to be me that has the problem.

avatar image Wolfrik_Creations · Jun 02, 2016 at 09:22 PM 0
Share

This worked flawlessly!

I'd searched for weeks/months trying to figure out how to fade a simple float, can't believe I was that stupid that I couldn't find this.

Then again, Google never shows anything relevant like I said before.

Couldn't figure out how to use SmoothDamp but $$anonymous$$oveTowards worked perfectly!

Now I just need to fade my day sky to my rainy sky and vise versa.

avatar image Alec-Slayden Wolfrik_Creations · Jun 03, 2016 at 01:27 AM 0
Share

happy to help :)

avatar image Wolfrik_Creations Alec-Slayden · Jun 03, 2016 at 01:28 AM 0
Share

Now it isn't $$anonymous$$inecraft! $$anonymous$$y weather actually fades!

avatar image
0

Answer by Zen_Hap · Jun 02, 2016 at 08:51 AM

@Wolfrik_Creation]

Use a float gradient which is what you are saying. Just google Unity float gradient and it will come up. It works in a similar way to what you put but is slightly longer.

I hope I helped!

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

64 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 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

Ensure that function only gets called once in a frame 2 Answers

4.6 - Using new GUI with JavaScript functions 1 Answer

Problem accessing variable in javascript 1 Answer

How to fade in/out the view of a specific Camera? 2 Answers

Script is causing immense lag, and I don't know what's causing it. 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