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 oliver-jones · Jan 22, 2012 at 04:17 AM · colorfadetint

Fade In _TintColor Over Time

Hello,

I have a game object that has a material attached to it. The material is a Particles/Alpha Bleneded, and by default, the Tint Color Alpha is set to 0.

What I want to be able to do, is to increase the Tint Color Alpha over time. Any ideas?

I've tried doing something like this:

 var increase = 0;
 var color : Color = Color(0.5, 0.5, 0.5, increase);
 
 renderer.material.SetColor ("_TintColor", color);
 
 for(var i = 0; i < 10; i++){
     increase = increase + 0.05;
     yield WaitForSeconds(0.01);
 }

But nothing happens. Please help!

Thanks

Comment
Add comment
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
0
Best Answer

Answer by Lo0NuhtiK · Jan 22, 2012 at 05:34 AM

 var color : Color ;
 var secondsToFade :float = 20 ;
 var red : float = 0.5 ;
 var green : float = 0.5 ;
 var blue : float = 0.5 ;
 var alpha : float = 0 ;
  
 function Update(){
    color = Color(red, green, blue, alpha) ;
    alpha = Mathf.Lerp(0, 1, Time.time / secondsToFade) ;
    renderer.material.SetColor("_TintColor" , color) ;
 }
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 Owen-Reynolds · Jan 22, 2012 at 04:24 PM 0
Share

Time.time is the time since the game started -- so this only works in the 1st 20 seconds. Add a startTime variable: alpha=(Time.time-startTime)/secondsToFade); In this case, don't really need the Lerp (a lerp turns a 0-1 into a different range, like 50 to 80.)

avatar image oliver-jones · Jan 22, 2012 at 09:25 PM 0
Share

@Owen Reynolds - Works well, but how would I add in specific color start - to end values? For example: increase the red from 0.5, to 1, over time? Thanks

avatar image oliver-jones · Jan 22, 2012 at 10:20 PM 0
Share

This only happens once. Is there a way to process the code more than once?

avatar image Owen-Reynolds · Jan 23, 2012 at 05:49 PM 0
Share

If you look at Loonkut's(sp) answer, the 0 and 1 in Lerp are the stop and start. You could extend that to use vars: if(Time.time<startTime+secondsToFade) Lerp(startVal, endVal, percentFormula); Whenever you want to go, set startTime to now, and startVal/endVal to whatever. It even works to fade from 1 to 0.

avatar image
0

Answer by .sanders · Jan 22, 2012 at 04:52 AM

I suggest using iTween which takes care of such thing for you:

http://itween.pixelplacement.com/index.php

It's pretty powerful and free to use... Read the documentation on how to use it. I think you might want to check on the ColorTo method.

hope this is useful

cheers!

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Fade out a line renderer? 1 Answer

Make a tilemap brighter/tint it white 0 Answers

Color tint on a shader. 1 Answer

How to make a "Click to Continue" text message? 1 Answer

Fading an image drawn with GUI.DrawTexture 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